- 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:54 AM
Hi Harry,
You are welcome, sometimes some small things won't be visible for our eyes even how many hours we spent also, while others easily find it out. I also come across such situation many times
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 12:44 PM
Hi
Where do you run this script? I am looking to do the same to clean up our environment from old request from previous years.
Do we use the Xplore: Developer Toolkit?
BTW - I am new ServiceNow stuff,