Skip to content

Commit 59f1b0d

Browse files
authored
Add GlideRecord example to query active incidents README.md
1 parent 9973350 commit 59f1b0d

File tree

1 file changed

+29
-0
lines changed
  • Core ServiceNow APIs/GlideRecord/Query Active Incidents

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# GlideRecord Example - Query Active Incidents
2+
3+
**Purpose:**
4+
Demonstrates how to use the `GlideRecord` API in a server-side script to query the **Incident** table for active records and print basic field values.
5+
6+
---
7+
8+
## Example Code
9+
10+
```js
11+
var gr = new GlideRecord('incident');
12+
gr.addQuery('active', true);
13+
gr.orderByDesc('sys_created_on');
14+
gr.setLimit(10);
15+
gr.query();
16+
17+
while (gr.next()) {
18+
gs.info('Number: ' + gr.getValue('number') +
19+
', Short Description: ' + gr.getValue('short_description') +
20+
', Assigned To: ' + gr.getDisplayValue('assigned_to'));
21+
}
22+
23+
var gr = new GlideRecord('incident'); Creates a new GlideRecord object for the Incident table
24+
gr.addQuery('active', true); Filters only active incidents
25+
gr.orderByDesc('sys_created_on'); Orders results from newest to oldest
26+
gr.setLimit(10); Limits the query to 10 records
27+
gr.query(); Executes the query
28+
while (gr.next()) Loops through each record found
29+
gs.info(...) Prints information to system logs

0 commit comments

Comments
 (0)