- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:43 PM
Hello ServiceNow community,
I hope you're doing well.
I've been practicing in my own developer instance and have been working on a solution for the prompt: "Query for all incidents created in the past 3 days where the caller is ‘Joe Employee’…log a count of records returned".
I provided a solution which I thought would work, but it provided my with a count of 0 records, which upon review should have provided me with a count of 10 that fit the parameters.
Please see an image of the business rule I scripted below. Let me know your thoughts and if I've made any errors. Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 11:01 PM
It's because of the line 7 from your script. Let's try to make this change.
From
gaIncident.addQuery('caller_id', 'Joe Employee');
To one of those
gaIncident.addQuery('caller_id', '<the_Joe_Employee_sys_id');
gaIncident.addQuery('caller_id.name', 'Joe Employee');
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 04:56 PM - edited 01-23-2024 04:58 PM
Hi @Philip Conforzi ,
You can always use the list view to construct filters. These filters you can use in GlideRecord.
I was able to create a filter on my PDI.
You can right click and copy the query, and use the gr.addEncodedQuery API.
"sys_created_onRELATIVEGT@dayofweek@ago@3"
var ga = new GlideAggregate('sn_hr_core_case');
ga.addEncodedQuery('sys_created_onRELATIVEGT@dayofweek@ago@3');
ga.addAggregate('COUNT');
ga.query();
if (ga.next()) {
var count = ga.getAggregate('COUNT');
gs.info('Number of HR Cases : ' + count);
}
Please change this to match your needs.
Please accept solution OR mark helpful.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 11:01 PM
It's because of the line 7 from your script. Let's try to make this change.
From
gaIncident.addQuery('caller_id', 'Joe Employee');
To one of those
gaIncident.addQuery('caller_id', '<the_Joe_Employee_sys_id');
gaIncident.addQuery('caller_id.name', 'Joe Employee');
Cheers,
Tai Vu