If else not working in calculation | Community
Skip to main content
ReluctantProgrammer
October 12, 2023
Solved

If else not working in calculation

  • October 12, 2023
  • 3 replies
  • 1806 views

My form has a Final Total Approved Reimbursement field that should show the lesser of three fields but I cannot get it to work.  I've looked at it so long I can find no reason for it not to. It should be simple enough (that's probably the reason I don't see the error). Here's the code:

 

if (Number(bottom.tblCourse.row8.reimbApproved.rawValue) < Number(bottom.tblReimbRcvd.row3.cost2Dec.rawValue))
{
this.rawValue = (bottom.tblCourse.row8.reimbApproved.rawValue);
}
else if (Number(bottom.tblCourse.row9.proRatedApproved.rawValue < Number(bottom.tblReimbRcvd.row3.cost2Dec.rawValue))
{
this.rawValue = (bottom.tblCourse.row9.proRatedApproved.rawValue);
}
else {
this.rawValue = (bottom.tblReimbRcvd.row3.cost2Dec.rawValue);
}

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Vijay_Katoch

Please use the below-modified script, which worked for me.

 

if (tblCourse.row8.reimbApproved.rawValue < tblReimbRcvd.row3.cost2Dec.rawValue)
{
this.rawValue = tblCourse.row8.reimbApproved.rawValue;
}
else if (tblCourse.row9.proRatedApproved.rawValue < tblReimbRcvd.row3.cost2Dec.rawValue)
{
this.rawValue = tblCourse.row9.proRatedApproved.rawValue;
}
else {
this.rawValue = tblReimbRcvd.row3.cost2Dec.rawValue;
}

3 replies

Vijay_Katoch
Community Advisor
Community Advisor
October 13, 2023

Please check the somExpression of fields if they are resolving properly. This may be the reason or you can share your form @ (vkatoch07@gmail.com), I'll have a look.

ReluctantProgrammer
October 13, 2023

My apologies.  I thought I had shared it but see it was blocked.  Here is the file.

Vijay_Katoch
Community Advisor
Vijay_KatochCommunity AdvisorAccepted solution
Community Advisor
October 16, 2023

Please use the below-modified script, which worked for me.

 

if (tblCourse.row8.reimbApproved.rawValue < tblReimbRcvd.row3.cost2Dec.rawValue)
{
this.rawValue = tblCourse.row8.reimbApproved.rawValue;
}
else if (tblCourse.row9.proRatedApproved.rawValue < tblReimbRcvd.row3.cost2Dec.rawValue)
{
this.rawValue = tblCourse.row9.proRatedApproved.rawValue;
}
else {
this.rawValue = tblReimbRcvd.row3.cost2Dec.rawValue;
}

kautuk_sahni
Community Manager
Community Manager
October 19, 2023

@vijay_katoch Did you find the suggestions from Vijay helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni
October 19, 2023

Hello,

 

Here is what I am seeing:

 

1. You are missing a ')' here: else if (Number(bottom.tblCourse.row9.proRatedApproved.rawValue< Number(bottom.tblReimbRcvd.row3.cost2Dec.rawValue))

2. You have a null variable error in your script object ColorFieldValidation, line 49:

TypeError: oOriginalNode is null

49:Doc:Init