top of page

Replace GlideRecord.getRowCount() in Server Script

Using GlideRecord.getRowCount() to count records in ServiceNow retrieves all matching rows, which can lead to performance and scalability issues as table sizes grow. This method unnecessarily processes all records, significantly impacting query efficiency. Instead, using GlideAggregate with the COUNT aggregate function improves performance by retrieving only the count without loading all records.


Resolution Steps

  1. Replace getRowCount() with GlideAggregate, which efficiently retrieves only the record count.

  2. Test for Accuracy and Performance

    1. Run the updated script in a test environment to verify that it returns the correct count.

    2. Compare execution times before and after implementation to observe performance improvements.


Before:

getRowCount() should be replaced
getRowCount() should be replaced

After:

GlideAggregate() efficiently retrieves only the record count.
GlideAggregate() efficiently retrieves only the record count.

By replacing getRowCount() with GlideAggregate, you improve performance and scalability by preventing unnecessary record retrieval. This optimization enhances query efficiency and reduces server load, making ServiceNow scripts more efficient.

For more detailed guidance on resolving this issue, please contact us at support@dt-advisory.ch.

bottom of page