Change RITM state if any SC_TASKS are on hold
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 08:50 AM
I looked through a couple of posts here and came up with a BR to place the RITM to 'Pending' if an SC_TASK was placed 'On Hold' but I can't seem to get it to work. I tried in two different ways. Can anyone shed light here?
Example 1
Example 2
(function executeRule(current, previous /*null when async*/) {
gs.addInfoMessage("current.state "+current.state);
var gr = current.request_item.getRefRecord();
if(current.state == -7){
gr.state ="Pending";
}
else{
gr.state ="In Progress";
}
gr.update();
gs.addInfoMessage("the set state is "+gr.state);
})(current, previous);
.
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 02:54 PM
If you want the RITM to not change State to In Progress if one of its tasks is Pending, then a script like this should do that:
(function executeRule(current, previous /*null when async*/) {
gs.addInfoMessage("current task state = " + current.state);
var gr = new GlideRecord('sc_req_item');
if (gr.get(current.request_item)) {
if (current.state == -5) { //Pending
gr.state = -5; //Pending
} else {
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', current.request_item);
sctask.addQuery('state', -5);
sctask.query();
if (!sctask.next()) {
gr.state = 2; //In Progress
}
}
gr.update();
gs.addInfoMessage("the RITM set state is " + gr.state);
}
})(current, previous);
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 03:04 PM
Thank you for that info. I wish SN forums had a tip jar!