- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 05:56 AM
Hello All,
I need a background script that will find any active approved RITM records that have no catalog tasks.
In our system, all approved requested items should have a catalog task but there are a lot of historical records that have none. I need to find all of these records.
I think a background script is the best way to achieve this but I'm not sure how it would work. I have a script that will find and print any RITM numbers that are active and approved:
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('active=true^approval=approved');
gr.query();
while (gr.next()) {
gs.print(gr.number);
}
Is there anything I can add to this script to return the RITM numbers that have no catalog tasks?
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
‎03-31-2017 06:12 AM
Harry,
Try below script.
var noTaskCounter = 0;
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('active=true^approval=approved'); //<-- whatever you want to filter on
gr.query();
while (gr.next()) {
//you could do a GlideAggregate here also.
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);
Output ex:
*** Script: RITM == RITM0000012 has Zero Tasks
*** Script: Out of 8 RITMs, only 1 had Zero Tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 06:15 AM
Correct me if i'm wrong but if there are no tasks for an RITM then running the query on the sc_task table wont work - because the tasks dont exist.
I need a list of all RITM records that dont have any catalog tasks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 06:20 AM
Not sure who you're replying to, but basically you want to loop through every request item in your instance and then check to see if it has any related tasks, which you do by query the sc_task table. If it doesn't have tasks then you would print the number or add it to an array of item numbers or something like that.