Calculating a field via business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2023 01:34 PM - edited 03-31-2023 01:42 PM
I am trying to populate an integer field on a table based on 5 other fields on that table, using a business rule; can't seem to get it to work so hoping someone can point out what I'm doing wrong.
The 5 other fields are of type "choice", but their values are just numbers.
The business rule I'm currently using is below, running on the specific table, and set to after (I've tried before as well). The conditions are set to when any of the 5 fields changes (just 5 or statements "or if field1, field2, etc changes"
(function executeRule(current, previous /*null when async*/) {
var total = parseInt(current.u_compliance_score) + parseInt(current.u_org_impact_score) + parseInt(current.u_patient_safety_score) + parseInt(current.u_productivity_score) + parseInt(current.u_revenue_impact_score);
current.u_clinical_optimization_score = total;
})(current, previous);
also tried this:
(function executeRule(current, previous /*null when async*/) {
var compliance_score = parseInt(current.getValue('u_compliance_score'));
var org_impact_score = parseInt(current.getValue('u_org_impact_score'));
var patient_safety_score = parseInt(current.getValue('u_patient_safety_score'));
var productivity_score = parseInt(current.getValue('u_productivity_score'));
var revenue_impact_score = parseInt(current.getValue('u_revenue_impact_score'));
var result = compliance_score + org_impact_score + patient_safety_score + productivity_score + revenue_impact_score;
current.u_clinical_optimization_score = result;
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 08:26 AM
NaN = Not a Number
So one of your values is Null or a string that cannot be parsed into a number.
You may want to do something like this for all of your variables. It will prevent a null and empty string values from being converted which can cause a NaN result.
var productivity_score = 0;
if(current.variables.productivity_score)
productivity_score = parseInt(current.variables.getValue('productivity_score'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 08:38 AM
Thanks, I'll give that a try now. Though the value of all these options are all numbers, so I'm not sure where it could be pulling a null value from.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 08:36 AM
hi @Staxed add .toString() to last line instead of above and try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2023 10:24 AM