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

Brad Bowman
Kilo Patron
Kilo Patron

Go with the script like example 2, but more like this - checking the State values in your environment vs OOTB that I have included:

(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 {
			gr.state = 2; //In Progress
		}
		gr.update();
		gs.addInfoMessage("the RITM set state is " + gr.state);
	}
})(current, previous);

@Brad Bowman that worked. I just realized however that I have some RITM's (not many) that have parallel tasks, if i place two tasks 'on hold' and then move one of them back out of 'on hold', i'm not sure how that is going to affect the RITM state here. Any suggestions?

 

Thanks again!

Hi @Russell Abbott ,

 

Yes, latest update will execute Business Rule and the RITM State will be updated back to WIP.

 

Just one more way to implement your requirement is by Flow Designer. Have you tried that?

Flow Designer is very easy to build, with no code, to build complex flow.

 

Try once with Flow Designer:

reshmapatil_0-1671473028887.pngreshmapatil_1-1671473065333.pngreshmapatil_2-1671473130577.png

 

reshmapatil_3-1671473169149.pngreshmapatil_4-1671473218406.png

 

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**

Thank you for your input here. We have a very complex Flow that was designed by a vendor when we had our implementation phase. I actually find Flow Designer to be very difficult to read. Part of that is more than likely my lack of training in that module, i found the older Workflow Editor much easier to understand.

With your notes however, I will look into that further