From e2b2fd168b785be603b9d7c2581a9cd078021a8e Mon Sep 17 00:00:00 2001 From: Rishan Menezes Date: Thu, 9 Oct 2025 23:54:33 +0530 Subject: [PATCH 1/2] Add incident count snippet Added incident_count.js file to demonstrate counting incident records using GlideRecord API --- .../GlideRecord/IncidentCount/incident_count.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Core ServiceNow APIs/GlideRecord/IncidentCount/incident_count.js diff --git a/Core ServiceNow APIs/GlideRecord/IncidentCount/incident_count.js b/Core ServiceNow APIs/GlideRecord/IncidentCount/incident_count.js new file mode 100644 index 0000000000..a0b03afb45 --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/IncidentCount/incident_count.js @@ -0,0 +1,5 @@ +// Count the number of incident records +var gr = new GlideRecord('incident'); +gr.query(); +var count = gr.getRowCount(); +gs.info('Total number of incidents: ' + count); From 6162b1e13b1072997fbced0d6086f68c870a2ce1 Mon Sep 17 00:00:00 2001 From: Rishan Menezes Date: Thu, 9 Oct 2025 23:55:33 +0530 Subject: [PATCH 2/2] Add README for incident count snippet Added comprehensive README documentation for the incident count snippet with usage examples and API references --- .../GlideRecord/IncidentCount/README.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Core ServiceNow APIs/GlideRecord/IncidentCount/README.md diff --git a/Core ServiceNow APIs/GlideRecord/IncidentCount/README.md b/Core ServiceNow APIs/GlideRecord/IncidentCount/README.md new file mode 100644 index 0000000000..922a6efb0a --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/IncidentCount/README.md @@ -0,0 +1,34 @@ +# Incident Count + +## Description +This snippet demonstrates how to count the total number of incident records in ServiceNow using the GlideRecord API. + +## Usage +This code can be run in: +- Background Scripts +- Script Includes +- Business Rules +- Scheduled Jobs + +## Code Example +```javascript +var gr = new GlideRecord('incident'); +gr.query(); +var count = gr.getRowCount(); +gs.info('Total number of incidents: ' + count); +``` + +## API Used +- GlideRecord - Core ServiceNow API for database operations +- getRowCount() - Returns the number of rows in the query result + +## Notes +- This snippet uses getRowCount() which is efficient for counting records +- The query() method must be called before getRowCount() +- You can add encoded queries before calling query() to count specific records + +## Related +- [GlideRecord Documentation](https://developer.servicenow.com/dev.do#!/reference/api/latest/server/no-namespace/c_GlideRecordScopedAPI) + +## Tags +#GlideRecord #Incidents #Count #ServerSide