Business Rule - IF condition checking for ZERO triggering on <empty>?

jlaps
Kilo Sage

Good morning community,

Trying to track down unexpected results from a change that went in and hoping for a sanity check.

We have a business rule that checks for a value of 0 on three fields (insert and update), and if correct, will set an IGNORE flag to 1 (true).

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

	// Add your code here
	if (current.u_inactive_kernels == 0 || current.u_non_running_services == 0 || current.u_not_exploitable_due_to_configuration == 0 )
		{
			current.u_ignore == 1;
			current.update();
		}

})(current, previous);

However, when the values of those three fields was set to <empty>, it appears to have triggered the IGNORE flag-

find_real_file.png

Is this expected? If so, how to prevent this since we are checking for if the value with '==' operator already. Is ZERO the same as <empty>?

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

What is the condition of the BR?

You can append the existing condition and add this with AND Operator that <FIELD ><IS NOT EMPTY>

-Anurag

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

those 3 fields are of what type?

I would suggest to use before update BR and don't use current.update() in BR

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

They are CHOICE fields, and their choices are-

find_real_file.png

try this

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

	// Add your code here
	if (current.u_inactive_kernels.toString() == '0' || current.u_non_running_services.toString() == '0' || current.u_not_exploitable_due_to_configuration.toString() == '0' )
	{
		current.u_ignore = 1;
	}

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I suggested to use Before BR and not After BR

Try above script

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader