How to get list of RITM which doesn't have any associated Ctasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 05:26 AM
Hello Folks,
I am trying to get list of RITMs which are opened 90 days ago, active true, approval is not waiting for approval and those RITMs doesn't have any Ctask associated with them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 05:53 AM
Hi @Vijay Baokar ,
Instead doing two glideRecords I would use glideAggregate for counting in the second one, check this about GlideAggregate: https://developer.servicenow.com/blog.do?p=/post/glideaggregate/
And, your code should look something as follows:
(function() {
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addEncodedQuery('stage!=waiting_for_approval^active=true^opened_atRELATIVELT@dayofweek@ago@90');
ritmGr.query();
while (ritmGr.next()) {
var Ctask = new GlideAggregate('sc_task');
Ctask.addAggregate('COUNT', 'request_item');
Ctask.addQuery('request_item', ritmGr.sys_id);
Ctask.query();
if(Ctask.getAggregate('COUNT') == 0){
gs.info('Ctask : ' + Ctask.getDisplayValue());
}
})();
☆ Community Rising Star 22, 23 & 24 ☆
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 06:02 AM
try the below code.
var noTaskCounter = 0;
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addEncodedQuery('stage!=waiting_for_approval^active=true^opened_atRELATIVELT@dayofweek@ago@90');
ritmGr.query();
while (ritmGr.next()) {
var Ctask = new GlideRecord('sc_task');
Ctask.addQuery('request_item', ritmGr.sys_id);
Ctask.query();
if(!Ctask.next()){
gs.info('Ctask Number: ' + ritmGr.number);
noTaskCounter++;
}
}
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 06:17 AM
@dgarad can we get the chunk of 100 record at a time ? i put the setLimit (100); but didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 06:34 AM
where do you apply setLimit?
Thanks
dgarad