Change RITM state if any SC_TASKS are on hold

Russell Abbott
Kilo Sage

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

br1.jpg

br2.jpg

 

Example 2

br3.jpgbr4.jpg

(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

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);

 

Thank you for that info. I wish SN forums had a tip jar!