Business Rule not working

ServiceNow Use6
Tera Guru

Hi,

 

I am trying to create a Business Rule for the incident matrix. Priority is not getting changed. Kindly help.

 

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

	var imp = current.u_impact.getValue();
	var urg = current.u_urgency.getValue();
	//var pri = current.u_priority;

	gs.info('impact is ' + imp + ' urgency is ' + urg);

	if((imp == '1')	 && (urg == '1')){
		current.u_priority = '1';
	}

	else if((imp =='1') && (urg == '2')){
	current.u_priority = '2';
   }

   else if((imp == '1') && (urg == '3')){
	current.u_priority = '3';
   }

   else if((imp == '2') && (urg == '1')){
	current.u_priority= '2';
   }

   else if((imp == '2') && (urg == '2')){
	current.u_priority='3';
   }

   else if((imp == '2') && (urg == '3')){
	current.u_priority='4';
   }

   else if((imp == '3') && (urg == '1')){
	current.u_priority='3';
   }

   else if((imp == '3') && (urg == '2')){
	current.u_priority = '4';
   }

   else if((imp == '3') && (urg == '3')){
	current.u_priority = '5';
   }
	

})(current, previous);
10 REPLIES 10

ServiceNow Use6
Tera Guru

Thank you, its working. I am stupid to not identify properly

@ServiceNow Use6 

 

Glad to know it worked !

 

As per community guidelines, you can accept more than one answer as accepted solution. If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

@ServiceNow Use6 

 

Did you get a chance to review this as provided information helped to resolve your issue.

 

As per community guidelines, you can accept more than one answer as accepted solution. If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

test218
Tera Contributor

The core issue is likely due to using assignment (current.u_priority = '1';) instead of the correct ServiceNow API method for updating GlideRecord fields in Business Rules—use .setValue() instead. Additionally, ensure the script is in a “before” Business Rule (not “after”), so the priority updates before the record is saved.

Corrected Script:

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

var imp = current.u_impact.getValue();
var urg = current.u_urgency.getValue();

gs.info('impact is ' + imp + ' urgency is ' + urg);

if ((imp == '1') && (urg == '1')) {
current.u_priority.setValue('1');
}
else if ((imp == '1') && (urg == '2')) {
current.u_priority.setValue('2');
}
else if ((imp == '1') && (urg == '3')) {
current.u_priority.setValue('3');
}
else if ((imp == '2') && (urg == '1')) {
current.u_priority.setValue('2');
}
else if ((imp == '2') && (urg == '2')) {
current.u_priority.setValue('3');
}
else if ((imp == '2') && (urg == '3')) {
current.u_priority.setValue('4');
}
else if ((imp == '3') && (urg == '1')) {
current.u_priority.setValue('3');
}
else if ((imp == '3') && (urg == '2')) {
current.u_priority.setValue('4');
}
else if ((imp == '3') && (urg == '3')) {
current.u_priority.setValue('5');
}

})(current, previous);

Important Considerations

  • Use setValue(): Always use current.field.setValue(value) for Business Rule field updates.

  • Business Rule Timing: Set the rule as “Before Update” or “Before Insert” so changes apply before record commit.

  • Field Names: Confirm that u_impact, u_urgency, and u_priority are the correct field names; otherwise, update accordingly.

  • Debugging: Keep gs.info or add gs.log statements to verify value assignments during troubleshooting.
    By implementing these changes and checks, the priority should now update correctly according to your impact/urgency matrix in ServiceNow.

Rafael Batistot
Kilo Patron

Hi @ServiceNow Use6 

 

Your Business Rule wasn’t updating Priority because of a couple of common pitfalls.

 

Here some fixes you need:

    1. Use the right field → OOB is priority, not u_priority (unless you created a custom one).
    2. Run the BR as Before Insert/Update so the system saves your value.
    3. Check your values: impact, urgency, and priority are choice fields with numeric strings ("1", "2", etc.).
    4. Be aware of OOB priority calculation (Priority Lookup Rules). They may override your BR if they run later.

 

(function executeRule(current, previous) {
var imp = current.impact;
var urg = current.urgency;

if (imp == '1' && urg == '1') current.priority = '1';
else if (imp == '1' && urg == '2') current.priority = '2';
else if (imp == '1' && urg == '3') current.priority = '3';
else if (imp == '2' && urg == '1') current.priority = '2';
else if (imp == '2' && urg == '2') current.priority = '3';
else if (imp == '2' && urg == '3') current.priority = '4';
else if (imp == '3' && urg == '1') current.priority = '3';
else if (imp == '3' && urg == '2') current.priority = '4';
else if (imp == '3' && urg == '3') current.priority = '5';
})(current, previous);