- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 10:13 PM
I want set RITM state based on the catalog task state. If catalog task state is Close complete. then RITM state also should change close complete. how i can do it.?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 08:48 PM
Hey,
You need to have a logic which will check all catalog tasks closed, before it goes ahead and close the RITM.
Table - Catalog Task(sc_task)
After - Update - State changed to Closed Complete.
How this BR runs, if your catalog tasks are closed, it will close the RITM, if your catalog tasks are incomplete or canceled, it will set the RITM as same.
var requestItem = current.getValue('request_item');
var closedCompleteSCTask = 0;
var closedSCTask = 0;
var scTask = new GlideRecord("sc_task");
scTask.addQuery("request_item", requestItem);
scTask.query();
var scTaskCount = scTask.getRowCount();
while(scTask.next()) {
var scTaskState = scTask.getValue('state');
if (scTaskState == 3) { // State is closed complete
closedCompleteSCTask++;
closedSCTask++;
}
if (scTaskState == 4 || scTaskState == 7) //State is closed incomplete or closed skipped
closedSCTask++;
}
if (closedSCTask == scTaskCount) {
if (closedCompleteWOT > 0)
closeRITM(3); // Set RITMstate = closed complete.
else
closeRITM(7); //Set RITM state = closed cancelled.
}
function closeRITM(state) {
var msg = '';
var ritmQuery= 'stateNOT IN3,4,7'; //State is not one of the Closed states
var requestItem= new GlideRecord('sc_req_item');
requestItem.addEncodedQuery(ritmQuery);
requestItem.addQuery('sys_id', wo);
requestItem.query();
if (requestItem.next()) {
requestItem.setValue('close_notes', msg);
requestItem.setValue('state', state);
requestItem.update();
}
}
})(current, previous);
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 08:32 PM
Hi,
did you try to debug that BR?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 08:48 PM
Hey,
You need to have a logic which will check all catalog tasks closed, before it goes ahead and close the RITM.
Table - Catalog Task(sc_task)
After - Update - State changed to Closed Complete.
How this BR runs, if your catalog tasks are closed, it will close the RITM, if your catalog tasks are incomplete or canceled, it will set the RITM as same.
var requestItem = current.getValue('request_item');
var closedCompleteSCTask = 0;
var closedSCTask = 0;
var scTask = new GlideRecord("sc_task");
scTask.addQuery("request_item", requestItem);
scTask.query();
var scTaskCount = scTask.getRowCount();
while(scTask.next()) {
var scTaskState = scTask.getValue('state');
if (scTaskState == 3) { // State is closed complete
closedCompleteSCTask++;
closedSCTask++;
}
if (scTaskState == 4 || scTaskState == 7) //State is closed incomplete or closed skipped
closedSCTask++;
}
if (closedSCTask == scTaskCount) {
if (closedCompleteWOT > 0)
closeRITM(3); // Set RITMstate = closed complete.
else
closeRITM(7); //Set RITM state = closed cancelled.
}
function closeRITM(state) {
var msg = '';
var ritmQuery= 'stateNOT IN3,4,7'; //State is not one of the Closed states
var requestItem= new GlideRecord('sc_req_item');
requestItem.addEncodedQuery(ritmQuery);
requestItem.addQuery('sys_id', wo);
requestItem.query();
if (requestItem.next()) {
requestItem.setValue('close_notes', msg);
requestItem.setValue('state', state);
requestItem.update();
}
}
})(current, previous);
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 08:54 AM
Hi @Aman Kumar S ,
Can you please explain where is this variable defined in this line(if (closedCompleteWOT > 0) - "closedCompleteWOT ")
and what is this variable defined in this line (
requestItem.addQuery('sys_id', wo); - "wo")
Regards,
Shalani R