- 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-11-2022 10:14 PM
Hi,
you can have after update BR on catalog task table
Condition: State Changes
Script:
var ritm = current.request_item.getRefRecord();
ritm.state = current.state;
ritm.update();
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-11-2022 10:42 PM
I applied this for one catalog but it seems not working. I had tired to change the state to CTASK complete but even RITM State was not change to change complete.
(function executeRule(current, previous /*null when async*/ ) {
var ritm = current.request_item.getRefRecord();
ritm.state = current.state;
ritm.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2022 11:14 PM
Hi,
are you sure there is no other BR on RITM which is blocking the update possibly since all catalog tasks under that RITM are not yet completed
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:06 PM
Ya there is no other business rule.
catalog tasks under that RITM are not yet completed --> There is only one task for now i have changed to complete . multiple tasks will trigger based on request type option selection. but challenge is RITM state is not getting change even CTASK is closed