- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2017 01:41 AM
Hello All,
I am trying to do a cleanup of some older RITM's that are effectively broken due to some workflow issues a few years back.
I have the following script that will find any RITM's that are approved but have no tasks:
var noTaskCounter = 0;
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('active=true^approval=approved');
gr.query();
while (gr.next()) {
var tsk = new GlideRecord('sc_task');
tsk.addQuery('request_item', gr.sys_id);
tsk.query();
if (!tsk.next()) {
gs.info('RITM == {0} has Zero Tasks',gr.number);
noTaskCounter++;
}
}
gs.info('Out of {0} RITMs, only {1} had Zero Tasks', gr.getRowCount(), noTaskCounter);
I can print the list of RITM's and manually update the records but there are a lot and would rather do this via a script.
What do I need to add into this script to update all the RITM's? Initially I will just be setting them to active=false
Many Thanks
Harry
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2017 01:45 AM
Hi Harry,
It is so simple, just add the gr.update in your script, it will update. Try something as below.
if (!tsk.next()) {
gs.info('RITM == {0} has Zero Tasks',gr.number);
gr.active =false;
gr.update();
noTaskCounter++;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2017 01:45 AM
Hi Harry,
It is so simple, just add the gr.update in your script, it will update. Try something as below.
if (!tsk.next()) {
gs.info('RITM == {0} has Zero Tasks',gr.number);
gr.active =false;
gr.update();
noTaskCounter++;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2017 01:48 AM
Hi Vinoth,
I have tried that and came here because I thought I was being stupid - it's not updating the records, it's still just printing the numbers.
Thanks
Harry

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2017 01:48 AM
Hi Harry,
Please check if this works
- var noTaskCounter = 0;
- var gr = new GlideRecord('sc_req_item');
- gr.addEncodedQuery('active=true^approval=approved');
- gr.query();
- while (gr.next()) {
- var tsk = new GlideRecord('sc_task');
- tsk.addQuery('request_item', gr.sys_id);
- tsk.query();
- if (!tsk.next()) {
- gs.info('RITM == {0} has Zero Tasks',gr.number);
- gr.active = false;
- gr.update();
- noTaskCounter++;
- }
- }
- gs.info('Out of {0} RITMs, only {1} had Zero Tasks', gr.getRowCount(), noTaskCounter);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2017 01:49 AM
I didnt use gr.update();
Now i feel like a fool
Thanks for your help