Business rule to set RITM state to "Closed Incomplete" when Catalog task is set to "Closed Incomplete"

G Balaji
Kilo Guru

Hi,

I have a catalog task associated with the Catalog item. If the catalog task state is set to "Closed Incomplete" or "Closed Skipped", I want to update the same to RITM state as well. I have writtten a business rule to accomplish this. Problem is, when I change the catalog task state to "Closed Incomplete" for the first time, RITM state is changed to "Work in Progress". What am I missing here?

Business Rule condition:

After Update Business rule

Condition: Stage changes to Closed Incomplete or State changes to Closed Skipped

Script:

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var gq=new GlideRecord('sc_req_item');
gq.addQuery('sys_id',current.request_item);
gs.log("Current request item is "+current.request_item);
gq.query();

if(gq.next()){
gs.log("Inside if");
gs.log("Current state of task is"+current.state);
gq.setValue('state',current.state);
gs.log("Current state of req_item is "+gq.state);
gq.update();
}

})(current, previous);

Thanks.

 

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

try changing your business rule to before instead of after.

View solution in original post

3 REPLIES 3

Mike Patel
Tera Sage

try changing your business rule to before instead of after.

Allen Andreas
Administrator
Administrator

Just throwing this out there, but are the values for those states the same?

As in a '2' for the task, is a 'what' for the item?

It may not be a 1 for 1.

And as the other person mentioned above, should be a before BR (before is best used when setting values).


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Harish Ragz
Kilo Guru

Create a Business Rule  for sc_task table with before run , check true for update and set a condition as State changes to Closed InComplete.

Once try the below script. It will help you.

(function executeRule(current, previous /*null when async*/) {
	
	var reqItem= new GlideRecord('sc_req_item');
	reqItem.addQuery('sys_id',current.request_item);
	reqItem.query();
	while(reqItem.next()){
		reqItem.setValue('state','4');
		reqItem.update();
		gs.addInfoMessage(reqItem.number);
	}
})(current, previous);

Please Hit ✅Correct(If it is a correct solution) or Hit ✅Helpful(If it is useful).