- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 09:21 AM
Hi everyone,
we have a requirement that, we want to update percentage based on two integer field value ,
so i have created After insert BR, but it's working , any suggestion that would be great help for me.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 09:49 AM
Hello @siva14
To calculate and update the percentage based on two integer fields, make sure to handle possible null values, division by zero, and ensure proper data types.
Here's an optimized version of your Business Rule:
(function executeRule(current, previous /*null when async*/) {
var mcatdemand = parseFloat(current.u_mcat_current_year_demand);
var mcatreturn = parseFloat(current.u_current_year_returns);
if (!isNaN(mcatdemand) && !isNaN(mcatreturn)) {
current.u_currentyearpercentagereturns = mcatreturn !== 0
? (mcatdemand / mcatreturn * 100).toFixed(2)
: 0;
} else {
current.u_currentyearpercentagereturns = 0; // Handle invalid data
}
})(current, previous);
Make sure this Business Rule runs After Insert or After Update based on your requirement.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 09:49 AM
Hello @siva14
To calculate and update the percentage based on two integer fields, make sure to handle possible null values, division by zero, and ensure proper data types.
Here's an optimized version of your Business Rule:
(function executeRule(current, previous /*null when async*/) {
var mcatdemand = parseFloat(current.u_mcat_current_year_demand);
var mcatreturn = parseFloat(current.u_current_year_returns);
if (!isNaN(mcatdemand) && !isNaN(mcatreturn)) {
current.u_currentyearpercentagereturns = mcatreturn !== 0
? (mcatdemand / mcatreturn * 100).toFixed(2)
: 0;
} else {
current.u_currentyearpercentagereturns = 0; // Handle invalid data
}
})(current, previous);
Make sure this Business Rule runs After Insert or After Update based on your requirement.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 11:33 AM
Hi @Juhi Poddar ,
thanks for the response, i have tried above script, still not updating percentage, and i have checked the field types, i am using percent complete as field type