Skip to content

Commit c96fc80

Browse files
authored
Add README for querying old records with GlideRecord
This README provides a guide on querying records older than a specified number of days using GlideRecord in ServiceNow. It includes details on the solution, usage context, implementation steps, and references to relevant APIs.
1 parent cdde65d commit c96fc80

File tree

1 file changed

+23
-0
lines changed
  • Core ServiceNow APIs/GlideRecord/Get Records Older than X Days

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Query records older than N days efficiently
2+
3+
## What this solves
4+
You often need to find records older than a threshold without loading the world into memory. This snippet:
5+
- Uses GlideDateTime maths to compute a date boundary
6+
- Uses encoded queries with index-friendly operators
7+
- Streams results and logs a compact summary
8+
9+
## Where to use
10+
Background Script, Script Include utility, or any server-side context.
11+
12+
## How it works
13+
- Compute a past date with GlideDateTime and subtract days
14+
- Build an encoded query like `opened_at<javascript:gs.daysAgoStart(n)` or a literal date
15+
- Limit fields with `addQuery` and `setLimit` when sampling
16+
17+
## References
18+
- GlideRecord API
19+
https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/GlideRecord/concept/c_GlideRecordAPI.html
20+
- GlideDateTime API
21+
https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/GlideDateTime/concept/c_GlideDateTimeAPI.html
22+
- GlideSystem date helpers
23+
https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/GlideSystem/reference/r_GlideSystem-date-methods.html

0 commit comments

Comments
 (0)