From 59f1b0d29a36e48d3006d1fa2ce54ee429b66da6 Mon Sep 17 00:00:00 2001 From: Divya <165976969+divyajetti9@users.noreply.github.com> Date: Mon, 6 Oct 2025 13:31:20 -0500 Subject: [PATCH] Add GlideRecord example to query active incidents README.md --- .../Query Active Incidents/README.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Core ServiceNow APIs/GlideRecord/Query Active Incidents/README.md diff --git a/Core ServiceNow APIs/GlideRecord/Query Active Incidents/README.md b/Core ServiceNow APIs/GlideRecord/Query Active Incidents/README.md new file mode 100644 index 0000000000..79bfecd8fc --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/Query Active Incidents/README.md @@ -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