- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 12:19 PM
I have a script and currently it is not working with GlideAggregate can someone please rectify it:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 01:15 PM - edited 11-22-2022 01:16 PM
Here is a script that can do that. Depending on the instance it's going for, amount of RITMs, active tasks and so on it might need to be tweaked. Perhaps even run as a flow instead and so on. I would also probably throw in some more checks in case there aren't any RITMs with state "in progress" or active tasks.
var RITM = new GlideRecord("sc_req_item");
RITM.addEncodedQuery("state=2"); //state is in progress
RITM.query();
var ritmSysids = [];
//Get all RITM sys_ids and put them in a array
while (RITM.next()) {
ritmSysids.push(RITM.getUniqueValue());
}
var checkTasks = new GlideRecord('sc_task');
checkTasks.addQuery('request_item','IN',ritmSysids);
checkTasks.addQuery('active',true);
checkTasks.query();
//Go through active tasks and remove the RITM from the array since it should only contain
//RITM with no active tasks
while(checkTasks.next()){
ritmSysids = ritmSysids.filter(function(item) {
return item != checkTasks.request_item
})
}
gs.info("Sys_ids of RITM with no active tasks: " + ritmSysids)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 01:17 PM
I would avoid dot-walking in an encoded query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 01:37 PM
@Goran WitchDoc , good to know. So would you always avoid using "RLQUERY"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 01:46 PM
If possible yes. To avoid the number of calls to the server. Same thing with your code below. Avoid having nestled glideRecord calls. What I mean is having a gliderecord query inside a while loop.
E.g. My code below does 2 calls to the server no matter how many tasks or RITMs there are. In your code, if there are 1000 RITMs, it does 1001 calls to the server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 02:01 PM
Thanks for the insight! I don't use "RLQUERY" that often but I have used it before in simple fix scripts solely for the convenience.
It would be helpful if ServiceNow had some documentation around "RLQUERY". It's my understanding that this is the same thing that's used for "Related List Conditions" in report builder. Also, I've seen several posts online of people promoting it as a useful "hidden" feature. I'll take your word and avoid it where possible but would love if ServiceNow could publish/document best practices around this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 02:14 PM
for reports, you probably don't have any other way around it and that is the way forward if you want to have it in there.