I want to set the Sc task state value to RITM state when state changes of Sc task

posasaihimahars
Tera Contributor
 
2 REPLIES 2

Samaksh Wani
Giga Sage
Giga Sage

Hello @posasaihimahars 

 

Write a BR :-

 

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

	var status = current.request_item.variables.comp_reviewStatus;
	var tr=new GlideRecord('sc_req_item');
tr.addQuery('sys_id',current.request_item);
tr.query();
tr.next();
    if (status == "under_review") {
		tr.state = 2;  // Work in Progress
tr.update();
	}
	else if (status == "awaiting_client") {
		tr.state = 5;  // Awaiting Client
tr.update();
	}
	else if (status == "completed") {
		tr.state = 2;  // Work in Progress
tr.update();
	}

})(current, previous);

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

Harish Bainsla
Kilo Patron
Kilo Patron
  1. Navigate to "Business Rules" in the ServiceNow application.

  2. Create a new Business Rule.

  3. Set the "Filter Conditions" to target the specific conditions when you want this rule to run (e.g., when the state changes).


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

if (current.state != previous.state) {

var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.ritm)) {

ritm.state = current.state;
ritm.update();
}
}
})(current, previous);