Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Need help with IF Statement!!!

Avatar

Level 2

I am trying to write an IF statement using FormCalc in LiveCycle. I have cell "tpe" which captures total points. I would like to assign levels based on the number of points achieved. For example, level I = 1001-1985; level II = 851-1000; level III = 551-850; level IV = <551. I want cell "level" to show either I, II, III or IV, based on the points in cell "tpe". How can I do this? I have zero familiarity with FormCalc or scrips in general. Can someone please help me with this? Would appreciate any help!! Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 7

Just put the script into the calculate field of level instead:

if (tpe > 1000 and tpe <= 1985) then

$ = "I"

elseif (tpe > 850 and tpe <= 1000) then

$ = "II"

elseif (tpe > 550 and tpe <= 850) then

$ = "III"

elseif (tpe  <= 550) then

$ = "IV"

else $ = ""

endif

Also just having a look at your form - for next time you could have saved yourself a whole lot of time in your setup by using tables for all those fields rather than making each one a seperate numeric field.

View solution in original post

15 Replies

Avatar

Level 7

in the exit event of "tpe" put:

if ($ > 1000 and $ <= 1985) then

level = "I"

elseif ($ > 850 and $ <= 1000) then

level = "II"

elseif ($ > 550 and $ <= 850) then

level = "III"

elseif ($ <= 550) then

level = "IV"

else level = ""

endif

(this assumes the user is entering the amount in the tpe cell. If it is worked out by a calculation you can use the same code but put it in a different event depending on what you are doing)

Avatar

Level 2

Thank you very much for your quick response! Although I've stopped getting all the syntax errors that my own feeble attempts were generating, the script didn't work.

"tpe" is a calculated - read only cell that sums the values of 10 other cells. I want the result I, II, III, or IV to appear in cell "level," based on the total in "tpe".  I tried different events as you suggested, but nothing. What can you suggest? Thanks in advance.

Avatar

Level 7

you can put that code in the calculation event of tpe after the code you already have to work out the value of tpe

Avatar

Level 2

Thank you so much!!! That worked...sort of. Now no matter what the sum of the 10 cells, "tpe" shows a result of zero and "level" shows as "IV". Am I missing something or doing something wrong?

Avatar

Level 7

level is showing as IV because tpe is 0. The code above does not change tpe so I am not sure why is has ruined your calculation. Can you post what you have in your calculation event?

Avatar

Level 2

This is what it says:

topmostSubform.Page3.tpe::calculate - (FormCalc, client)

sum (rrtotal, programtotal, financetotal, leadershiptotal, executivetotal, meetingstotal, filestotal, brotherhoodtotal, conferencetotal, communicationstotal, minutestotal, standardstotal, basileustotal, abtotal, gramtotal, antigramtotal, tamtotal, pgramtotal, partotal, epistotal, torchtotal, hodtotal, phitotal)

if ($ > 1000 and $ <= 1985)then

level = "I"

elseif ($ > 850 and $ <= 1000)then

level = "II"

elseif ($ > 550 and $ <= 850)then

level = "III"

elseif ($ <= 550)then

level = "IV"

else level = ""

endif

Avatar

Level 7

try putting $ = before your sum:

$ = sum (rrtotal, programtotal, financetotal, lead.....

Avatar

Level 2

That didn't work. It calculates correctly if I remove the IF statement, but not with it. I even tried recreating the cells in a brand new form, but it again only works without the IF. Is it possible for me to send the form to you to look at?

Avatar

Level 7

sure post it online and I will have a look.

Avatar

Level 2

Forgive my ignorance, but I don't see how to do this. How do I upload the file on here?

Avatar

Level 2

Did you forget about me? Still need help. How can i upload the file to you? Thanks.

Avatar

Level 7

You can upload your file on acrobat.com

Avatar

Level 2

Wow, never knew about acrobat.com. Here's the link. The cells in question are on page 3 titled "TOTAL POINTS EARNED" and "CHAPTER LEVEL ATTAINED." "tpe should show the total points earned and "level" should show the level based on the points in tpe. Thanks so much for the help you've given. Sorry to be a pest.

https://files.acrobat.com/a/preview/ef14186f-7ba4-4033-ae5f-e37f6563d43a

Avatar

Correct answer by
Level 7

Just put the script into the calculate field of level instead:

if (tpe > 1000 and tpe <= 1985) then

$ = "I"

elseif (tpe > 850 and tpe <= 1000) then

$ = "II"

elseif (tpe > 550 and tpe <= 850) then

$ = "III"

elseif (tpe  <= 550) then

$ = "IV"

else $ = ""

endif

Also just having a look at your form - for next time you could have saved yourself a whole lot of time in your setup by using tables for all those fields rather than making each one a seperate numeric field.

Avatar

Level 2

Yes!!!! It worked!! Thank you so much for your help! Really appreciate it!.

I have zero experience with LiveCycle, so the form was made in InDesign, then exported as pdf. As I get more familiar with LiveCycle, I will definitely take your advice. Again, thanks a lot.