Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Core ServiceNow APIs/GlideRecord/Query Active Incidents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# GlideRecord Example - Query Active Incidents

**Purpose:**
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.

---

## Example Code

```js
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.query();

while (gr.next()) {
gs.info('Number: ' + gr.getValue('number') +
', Short Description: ' + gr.getValue('short_description') +
', Assigned To: ' + gr.getDisplayValue('assigned_to'));
}

var gr = new GlideRecord('incident'); Creates a new GlideRecord object for the Incident table
gr.addQuery('active', true); Filters only active incidents
gr.orderByDesc('sys_created_on'); Orders results from newest to oldest
gr.setLimit(10); Limits the query to 10 records
gr.query(); Executes the query
while (gr.next()) Loops through each record found
gs.info(...) Prints information to system logs
Loading