Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

if then calc

Avatar

Level 2

I have a numeric field that calculates

a total.  I have a text field that I want to look at the nume

ric field and based on what the

number field says enter text.

This is what I have for my calc right now...its not working...I don't know if it should be formcalc or java

if

(TextField2.rawValue == 16 or 17 or 18 or 19 or 20 or 21 or 22 or 23 or 24 or 25)

{

this.rawValue

= "Low Risk"

}

else

(TextField2.rawValue == 26 or 27 or 28 or 29 or 30 or 31 or 32 or 33)

{

this.rawValue

= "Moderate Risk"

}

else

(TextField2.rawValue == 34 or 35 or 36 or 37 or 38 or 39 or 40 or 41 or 42)

{

this.rawValue

= "High Risk"

}

1 Accepted Solution

Avatar

Correct answer by
Level 3

I don't believe the syntax works for either formcalc or javascript.  I don't use formcalc much, but in js you would need to do an else if :

if (TextField2.rawValue == 16 | TextField2.rawValue == 17 | etc etc put those other values in here)

{

     this.rawValue = "Low Risk";

}

else if (TextField2.rawValue == 26 | TextField2.rawValue == 27 | etc etc)

{

     this.rawValue = "Moderate Risk";

}

else if (TextField2.rawValue == 34 | TextField2.rawValue == 35 | etc etc)

{   

     this.rawValue = "High Risk";

}

That's just one way.  You could also setup variables and do a for loop, or even do a bunch of case statements using switch.  This above is easy just takes a lot of ors.  You need to make sure you explicitly state TextField2.rawValue == for every or, which is the | symbol.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 3

I don't believe the syntax works for either formcalc or javascript.  I don't use formcalc much, but in js you would need to do an else if :

if (TextField2.rawValue == 16 | TextField2.rawValue == 17 | etc etc put those other values in here)

{

     this.rawValue = "Low Risk";

}

else if (TextField2.rawValue == 26 | TextField2.rawValue == 27 | etc etc)

{

     this.rawValue = "Moderate Risk";

}

else if (TextField2.rawValue == 34 | TextField2.rawValue == 35 | etc etc)

{   

     this.rawValue = "High Risk";

}

That's just one way.  You could also setup variables and do a for loop, or even do a bunch of case statements using switch.  This above is easy just takes a lot of ors.  You need to make sure you explicitly state TextField2.rawValue == for every or, which is the | symbol.

Avatar

Level 7

if you want to do it in formcalc it could look like this:

if (NumericField1 >= 16 and NumericField1 <=25) then
    $ = "Low Risk"
elseif (NumericField1 >= 26 and NumericField1 <=33) then
    $ = "Moderate Risk"
elseif (NumericField1 >= 34 and NumericField1 <=42) then
    $ = "High Risk"   
endif

just make sure the box where they enter the number is a numeric field not a text field (like in your example).

Avatar

Level 2

Thank you...

How do you get that symbol to show up.  The one that means every or?