- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 03:26 AM
Hello All,
I need to create a Scheduled job to close the RITM for one particular catalog item only, when all the catalog task are closed then RITM should be closed.
Note: The catalog item has 5 catalog tasks
Thanks in Advance
Avinash
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 03:53 AM
something like this. I hope you can enhance it further.
closeRITM();
function closeRITM(){
try{
var gr = new GlideRecord("sc_req_item");
gr.addActiveQuery();
gr.addQuery("cat_item.name", "Your Catalog Item Name Here");
gr.addQuery("name", "value");
gr.query();
while (gr.next()) {
var taskRec = new GlideRecord("sc_task");
taskRec.addActiveQuery();
taskRec.addQuery("request_item", gr.getUniqueValue());
taskRec.setLimit(1);
taskRec.query();
if(!taskRec.hasNext()){
// there are no active tasks for this RITM so close it
gr.state = 3;
gr.active = false;
gr.update();
}
}
}
catch(ex){
gs.info(ex);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 03:49 AM
so what script did you start with?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 03:53 AM
something like this. I hope you can enhance it further.
closeRITM();
function closeRITM(){
try{
var gr = new GlideRecord("sc_req_item");
gr.addActiveQuery();
gr.addQuery("cat_item.name", "Your Catalog Item Name Here");
gr.addQuery("name", "value");
gr.query();
while (gr.next()) {
var taskRec = new GlideRecord("sc_task");
taskRec.addActiveQuery();
taskRec.addQuery("request_item", gr.getUniqueValue());
taskRec.setLimit(1);
taskRec.query();
if(!taskRec.hasNext()){
// there are no active tasks for this RITM so close it
gr.state = 3;
gr.active = false;
gr.update();
}
}
}
catch(ex){
gs.info(ex);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 04:17 AM
Kudos Ankur !