Article : GlideRecord Task Sheet (All important methods in task-based questions)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago - last edited 5 hours ago
Hello Community Members,
I’m sharing a GlideRecord Task Sheet that covers the most important methods used in both GlideRecord and GlideAggregate. These are designed as task-based questions so you can practice hands-on and strengthen your scripting skills.
👉You can try out all of these in Background Scripts on your PDI.
Important Note -
Before attempting these tasks, please go through the GlideRecord API and GlideAggregate API documentation/methods to understand their usage.
All of the questions provided are based on the incident table in ServiceNow and are designed to help you practice hands-on in Background Scripts.
Beginner (Basics of GlideRecord) -
1. Retrieve any 5 active incidents and print their number and short_description.
2. Fetch one incident using its sys_id.
3. Check if a particular incident exists using isValidRecord().
4. Count how many total incidents exist.
5. Insert a new incident with short_description = "Test Incident" and priority = 2.
6. Query incidents where priority = 1 OR priority = 2 usingaddOrCondition().
7. Update the state of one incident from New to In Progress.
8. Retrieve any 5 active incidents and Sort by sys_created_on descending.
9. For any particular incident print caller name instead of caller sys_id.
10. Delete any one incident from the table.
Intermediate -
1. Retrieve incidents where short_description contains the word "email". (You can choose any specific word as per your instance records).
2. Bulk update all Priority 5 incidents to Priority 4.
3. Fetch all inactive incidents and delete them in bulk using a loop.
4. Use addQuery() twice to get incidents where priority = 1 AND active = true.
5. Get the oldest incident created.
6.Create a new incident where caller_id is set to your own user sys_id. Set short_description = "Raised by script.Print the caller’s display value along with the new incident number.
7. Find all incidents where caller_id is empty.
8. Get the GlideRecord object and check if a specific field exists using isValidField().
9. Print both raw values and display values for priority field.
10. See the use case of these 2 methods and the differences - newRecord() and initilize ().
Advanced -
1. Write a script to close all Priority 5 incidents in bulk.
2. Change the assignment group for all active P1 incidents to “Service Desk”
3. Copy values from one incident to another (caller, short_description).
4. Find incidents with attachments (sys_attachment table join)
5. Get the top 3 callers who raised the most incidents (use GlideAggregate).
6. Count total number of active incidents (GlideAggregate COUNT).
7. Find the earliest and latest created incidents (GlideAggregate MIN/MAX).
8. Calculate the average priority value of all incidents (GlideAggregate AVG).
9. Find the sum of business_duration of resolved incidents (GlideAggregate SUM).
10. Query 2 different tables (incident + problem) and print related data.
11. Find incidents where state is (1,2,3). (Using in operator).
12. Build a reusable function that accepts a priority number and returns all matching incidents.
13. Write a script that checks if an incident exists — if not, create one.
14. Use hasNext() instead of while(next()) to control iteration.
15. Use encodedQuery() to fetch incidents where priority=1^active=true.
16. Export all incident numbers and descriptions into a comma-separated string.
17. Use GlideAggregate to count incidents where SLA breached = true.
18. Write a script using OR + AND conditions: fetch all incidents where (priority = 1 OR priority = 2) AND active = true.
19. Use GlideAggregate to count incidents by priority (groupBy('priority')).
20. Fetch incidents created in the last 7 days.
Expert Level (5 Bonus) – Real Interview Scenarios -
1. Find the top 3 callers who raised the most incidents.
2. Fetch incidents that have no work notes added.
3. Write a script to back up incidents into a custom table using GlideRecord copy.
4. Use GlideAggregate to calculate incidents count grouped by priority and state.
5. Find the average priority of all active incidents.
Note - Please feel free to reply if you have any doubts or concerns.
If you find this task sheet useful, please mark it as Helpful and share it with your fellow developers so they can also practice and benefit from it. 🙌
Shashank Jain