- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 10:57 AM
Hi,
I have a requirement where the state of the RITM should be the same as the SCTask. When the SCTask is set to Closed incomplete, the RITM should show state as Closed Incomplete, if the SCTask is set to Closed Skipped, the RITM should show state as Closed Skipped, SCTask is set to Closed Complete, the RITM should show state as Closed Complete.
I have tried the workflow route and business rules route but nothing seems to be working.
Any help would be appreciated.
Thanks,
Mallika
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 11:37 AM
Line number 10 is incorrect in your script. Please use the exact version of script as shared above. You don't need to hard code any sys id there.
Please use the exact script with no change required here.
Sharing it again for reference below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(current.state.changes()){
updateRITMState(current.request_item,current.state);
}
function updateRITMState(RitmID,state){
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',RitmID);
gr.query();
if(gr.next()){
gr.state = state;
gr.update();
}
}
})(current, previous);
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 11:57 AM
Hi
That worked like a charm!
Another question - can we use a similar script to show the state on the Request as Closed Complete, Closed Incomplete and Closed Skipped?
Thanks,
Mallika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 12:08 PM
Nope you need to update the same script as below:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if (current.state == 2 || current.state == 3) {
updateRITMState(current.request_item, current.state);
updateRequestState(current.request_item.request, current.state);
}
function updateRITMState(RitmID, state) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', RitmID);
gr.query();
if (gr.next()) {
gr.state = state;
gr.update();
}
}
function updateRequestState(requestID, state) {
var gr = new GlideRecord('sc_request');
gr.addQuery('sys_id', requestID);
gr.query();
if (gr.next()) {
gr.state = state;
gr.setWorkflow(false);
gr.update();
}
}
})(current, previous);
This will ensure when ever you update a state of a catalog task the same will get updated both in Requested Item and Request form as well.
This is working fine for me in my PDI.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke