
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:30 PM
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);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 02:22 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:35 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:37 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 02:22 PM
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);