- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2018 07:39 AM
Hi,
I have written a business rule to compare two currency field values and which ever is lesser among them, should be used to set a value of another field.
Total Credit Amount is compared against
Below is the script that I am using in an on before, business rule.
(function executeRule(current, previous /*null when async*/) {
var maxcap = current.eli_cre_amt.getCurrencyValue();
var totalcredit = current.tc_a.getCurrencyValue();
if (totalcredit < maxcap){
current.app_credit.setDisplayValue(totalcredit);
gs.addInfoMessage(totalcredit);
}
else
{
current.app_credit.setDisplayValue(maxcap);
gs.addInfoMessage(maxcap);
}
The issue is, it is setting the Maximum credit amount instead of Total Credit amount. (here total credit amount is lesser than maximum credit amount) see the screenshot attached.
Regards,
Narmi
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2018 11:47 AM
The issue is that getCurrencyValue() returns a string, so you are doing a lexical comparison. In other words:
"4.63" < "7.24" because four lexically comes before seven. However,
"14.63" < "7.24" because one lexically comes before seven. It never gets to the second digit.
To fix this, you need to convert the value string into a number. You can do it like this:
(function executeRule(current, previous /*null when async*/) {
var maxcap = parseFloat(current.eli_cre_amt.getCurrencyValue());
var totalcredit = parseFloat(current.tc_a.getCurrencyValue());
if (totalcredit < maxcap) {
current.app_credit.setDisplayValue(totalcredit);
gs.addInfoMessage(totalcredit);
}
else {
current.app_credit.setDisplayValue(maxcap);
gs.addInfoMessage(maxcap);
}
})();
Hope this helps,
--Dennis R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2018 11:47 AM
The issue is that getCurrencyValue() returns a string, so you are doing a lexical comparison. In other words:
"4.63" < "7.24" because four lexically comes before seven. However,
"14.63" < "7.24" because one lexically comes before seven. It never gets to the second digit.
To fix this, you need to convert the value string into a number. You can do it like this:
(function executeRule(current, previous /*null when async*/) {
var maxcap = parseFloat(current.eli_cre_amt.getCurrencyValue());
var totalcredit = parseFloat(current.tc_a.getCurrencyValue());
if (totalcredit < maxcap) {
current.app_credit.setDisplayValue(totalcredit);
gs.addInfoMessage(totalcredit);
}
else {
current.app_credit.setDisplayValue(maxcap);
gs.addInfoMessage(maxcap);
}
})();
Hope this helps,
--Dennis R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2018 11:03 PM
Thank You, Dennis.
Works brilliantly!
Regards,
Narmi