Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Change SCTASK state in Work in Progress when assgned to field is true

NDIAYE
Tera Contributor

Hello Community,

 

I would like to set a BR on RITM, When the assigned to field is true, then the SCTASK state change to WIP.

Thanks for your input.

1 ACCEPTED SOLUTION

Kai Tingey
Tera Guru

@NDIAYE you can achieve this with a business rule on the sc_req_item table

 

set it to run on update when assigned_to changes (you can change this to whatever fits your requirements best)

KaiTingey_0-1698292382700.png

 

and have it run this script:

 

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

	if (current.assigned_to != ''){

		//query sc_task table
		var sctask = new GlideRecord('sc_task');
		sctask.addQuery('request_item',current.sys_id);
	
		//update state
		sctask.setValue('state',2);
		sctask.updateMultiple();

		//notify fulfiller
		gs.addInfoMessage('Updated state of child tasks');
	}
})(current, previous);

 

if the assigned to has changed, and the new value is not empty, it will query sc_task table for any records associated with that request item, update the state and add an info message.

View solution in original post

6 REPLIES 6

Kai Tingey
Tera Guru

@NDIAYE you can achieve this with a business rule on the sc_req_item table

 

set it to run on update when assigned_to changes (you can change this to whatever fits your requirements best)

KaiTingey_0-1698292382700.png

 

and have it run this script:

 

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

	if (current.assigned_to != ''){

		//query sc_task table
		var sctask = new GlideRecord('sc_task');
		sctask.addQuery('request_item',current.sys_id);
	
		//update state
		sctask.setValue('state',2);
		sctask.updateMultiple();

		//notify fulfiller
		gs.addInfoMessage('Updated state of child tasks');
	}
})(current, previous);

 

if the assigned to has changed, and the new value is not empty, it will query sc_task table for any records associated with that request item, update the state and add an info message.

Hi @Kai Tingey  Thanks so much for your help here

 

Your proposal looks like what I expected. I will test it shortly and will be back to you.