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
Replace getRowCount() with GlideAggregate, which efficiently retrieves only the record count.
Test for Accuracy and Performance
Run the updated script in a test environment to verify that it returns the correct count.
Compare execution times before and after implementation to observe performance improvements.
Before:

After:

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.