File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Core ServiceNow APIs/GlideRecord/Query Active Incidents Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments