Business Rules: Calculated Field Value

Desmo
Mega Guru

Hello,

Need help with a Business Rule script to calculate the value of a field based on other fields and calculations.

Conditions set in 'When to run'.

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

	// Add your code here
	var price = current.u_price; // List price in $$
	var years = current.u_term / 12; // Convert months into years
	var yes = 'Yes';
	var no = 'No';
	
	if (price / years >= 40000); //Price divided by years is equal or greater than 40k
	{
	current.u_entitlement = 'yes'); //Display 'Yes' or 'No' in field
	}
    else { 
	current.u_entitlement = no;
			
		}			
	}
)(current, previous);
1 ACCEPTED SOLUTION

Desmo
Mega Guru

Solution:

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

	// Add your code here
	var price = current.u_price; // List price in $$
	var years = current.u_term / 12; // Convert months into years
	var yes = 'Yes';
	var no = 'No';
	
	if (price / years >= 40000) //Price divided by years is equal or greater than 40k
	{
	current.u_entitlement = yes; //Display 'Yes' or 'No' in field
	}
    else { 
	current.u_entitlement = no;
			
		}			
	}
)(current, previous);

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

small correction in your script; you can try now if it works

I consider this to be before insert BR

current.u_entitlement = yes;

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

use the following script:

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

	// Add your code here
	var price = current.u_price; // List price in $$
	var years = current.u_term / 12; // Convert months into years
	var yes = 'Yes';
	var no = 'No';
	
	if (price / years >= 40000); //Price divided by years is equal or greater than 40k
	{
	current.u_entitlement = yes; //Display 'Yes' or 'No' in field
	}
    else { 
	current.u_entitlement = no;
			
		}			
	}
)(current, previous);

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

Desmo
Mega Guru

Solution:

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

	// Add your code here
	var price = current.u_price; // List price in $$
	var years = current.u_term / 12; // Convert months into years
	var yes = 'Yes';
	var no = 'No';
	
	if (price / years >= 40000) //Price divided by years is equal or greater than 40k
	{
	current.u_entitlement = yes; //Display 'Yes' or 'No' in field
	}
    else { 
	current.u_entitlement = no;
			
		}			
	}
)(current, previous);