Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Nested If Statement or something else?

Avatar

Level 1

Hi - I'm a newbie to LiveCycle Designer and only have limited knowledge of coding.

I have a form that is used to determine cost based on the age.   I am unable to get the FormCalc syntax to operate properly.

This is what I have so far:

var ARate

var cost

if ( not VolEEAmount.isNull ) then

    if ( InvisibleEEAgeCalField.rawValue < 29) then ARate eq ".0075";

            elseif ( InvisibleEEAgeCalField.rawValue > 29 and InvisibleEEAgeCalField < "34" ) then ARate eq ".001";

    endif

cost = ( ARate * VolEEAmount.rawValue )

else

    cost = ""

endif

VolEEAmount is a numeric field and where the person enters a number.  The number they enter will drive the calcuation of how much they need to pay

InvisibleEEAgeCalField is an invisible numeric field where I've determine the person's age.  It's hidden for all views.

What am I doing wrong?  Any tips is welcomed  Thanks in advance

1 Accepted Solution

Avatar

Correct answer by
Level 1

I resolved it through my mentor. Here's the fix I got:

if ( HasValue(VolEEAmount) ) then

    if ( Within(InvisibleEEAgeCalField.rawValue, 0, 29) ) then  0.000075 * VolEEAmount.rawValue else

    if ( Within(InvisibleEEAgeCalField.rawValue, 30, 35) ) then 0.000100 * VolEEAmount.rawValue else

0.000200 * VolEEAmount.rawValue

     endif

    endif

else

    Null

endif

Good luck and hope this will help someone in the future.

View solution in original post

4 Replies

Avatar

Level 7

what are you doing with the value of your variables once the script is complete? At the moment they are not showing anywhere. Also where have you put this script?

Avatar

Level 1

Thanks for your response!

Let me add some more info:

Say my birthday is 02/28/1980.  It's entered in a date/time field. 

I want to elect 100,000 coverage in life insurance.  The rates are as follow:

Beginning AgeEnding AgeRate (monthly)
029.000075
3034.000075
3539.000105
4044.000155
4549.000225
5054.000415
5559.000645
6064.000735
6569.001255
7074.003075
7599.012005

My age = 32 --> refers to the table the rate is .000075

I have a hidden field called "InvisibleEEAgeCalField" that uses another FormCalc code to determine age.  The syntax is as follow:

if ( not EEInfoSubform.EEInfoTable.Row1.DOB.isNull ) then

    var dateofBirth = Date2Num( EEInfoSubform.EEInfoTable.Row1.DOB, "YYYY-MM-DD" )

    var currentDate = Date()

    var years = ( currentDate - dateofBirth ) / 365

    $ = Floor( years )

else

    $ = ""

endif

I input "100,000" into a numeric field call "VolEEAmount

I want the numeric field called "VolEECost" to display the calculation below:

rate of .000075 multiple by the "VolEEAmount"  [.000075x100,000] -> display 7.50 in the numeric field "VolEECost"

Avatar

Level 1

Hello Everyone - I simplified my logic statements. 

What is wrong with this syntax?

var ARate = .000075

var BRate = .0001

var age = if ( HasValue(EEInfoSubform.EEInfoTable.Row1.DOB) ) then Floor( ( Date() - Date2Num( EEInfoSubform.EEInfoTable.Row1.DOB, "YYYY-MM-DD" )) / 365 ) else Null endif  //this give me the age

var Rate = if ( age < 29) then ARate   elseif ( age > 29 and age < 34 ) then BRate    endif  //this sets the rate

if ( HasValue(VolEEAmount) ) then  

Rate * VolEEAmount.rawValue

else

    NULL

endif

Avatar

Correct answer by
Level 1

I resolved it through my mentor. Here's the fix I got:

if ( HasValue(VolEEAmount) ) then

    if ( Within(InvisibleEEAgeCalField.rawValue, 0, 29) ) then  0.000075 * VolEEAmount.rawValue else

    if ( Within(InvisibleEEAgeCalField.rawValue, 30, 35) ) then 0.000100 * VolEEAmount.rawValue else

0.000200 * VolEEAmount.rawValue

     endif

    endif

else

    Null

endif

Good luck and hope this will help someone in the future.