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

IF ... Else statement formula help needed

Avatar

Former Community Member

Hi, I have a table with several colums and I need to perform a simple calculations between them the scrip for it looks like this

form1.#subform[0].SubTable.Table1.Row[0].Total::calculate - (FormCalc, client)

if (AmountNet > 0) then
     Total = AmountNet + VAT
elseif (AmountNet == 0) then
     Total = AmountForeign * ExchangeRate
endif

for some reason the first part of the staement is working I cannot figure it out why second part does not.

Can some one advise please?

Thanks a lot

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Put an app.alert(AmountNet.rawValue) before the if statement. This will show you the value of the AmountNet in a message box.....maybe it is not 0 like you think?

Why are you doing an else if statement anyways ......unless they can enter a negative value (which I doubt as this seems to be a monetary calculation). If it is greater than 0 then you are fine else it must be 0 and there is no need to have another if statement. So it woudl look like this:

if (AmountNet > 0) then
     Total = AmountNet + VAT
else (AmountNet == 0)

     Total = AmountForeign * ExchangeRate
endif

Paul

View solution in original post

10 Replies

Avatar

Correct answer by
Former Community Member

Put an app.alert(AmountNet.rawValue) before the if statement. This will show you the value of the AmountNet in a message box.....maybe it is not 0 like you think?

Why are you doing an else if statement anyways ......unless they can enter a negative value (which I doubt as this seems to be a monetary calculation). If it is greater than 0 then you are fine else it must be 0 and there is no need to have another if statement. So it woudl look like this:

if (AmountNet > 0) then
     Total = AmountNet + VAT
else (AmountNet == 0)

     Total = AmountForeign * ExchangeRate
endif

Paul

Avatar

Former Community Member

Paul,

would you be able to help me with this one as well, please?

form1.SubTable.Table2.Row1[0].Total::calculate - (FormCalc, client)
if (AmountNet > 0) then
     Total = AmountNet + VAT
else (AmountNet == 0) and (ExchangeRate > 0)
     Total = AmountForeign /ExchangeRate
endif

it still gives me an error.

Thanks

Alex

Avatar

Former Community Member

Can you post the form so I can debug it?

Paul

Avatar

Level 4

hi, sorry to jump in on someone else thread but i see its answered and very similar to my issue which is

in javascript

im trying to get certain field values and use if else if ladder to evaluate and then specify a fields value bases on that

this needs to take values from radio button groups and lists and some user enterd also -

have tried to work it thorugh logically  and guess it whould look about like

if( A.rawValue == "1" && B.rawValue == "1) {
formclass.rawValue == "targetA";
} else if( A.rawValue == "0" && B.rawValue == "0" ) {
formclass.rawValue == "targetB";
}

where for testing purposes im trying to get the formclass value to be displayed in a text feild

i dont know whether i should be using some command to get the values first up or whats wrong -- but it just sits there looking at me when i click the button (set to dynamic preview and saved as dynamic pdf) .......

any chance of some pointers, please....................!!

Avatar

Level 10

Hi,

Just a quick check:

When testing against a criteria use "=="

When assigning a value (rawValue) use "="

It's too late to go into triple opperators, but I would recommend "JavaScript - the definitive guide" 5th edition, edited by David Flanagan.

N.

Avatar

Level 4

Thanks Niall

I checked it with the == changed to = and it's still dead.....

I will google for a copy of the book you suggested - thanks

Avatar

Level 10

just for clarity, it would look like:

if( A.rawValue == "1" && B.rawValue == "1") {
formclass.rawValue = "targetA";
} else if( A.rawValue == "0" && B.rawValue == "0" ) {
formclass.rawValue = "targetB";

}

Check out the b.rawValue that in the actual script it has the closing "

N.

Avatar

Level 4

Niall,

Once again thank you. That is now working; I was using either == or = not

the "==" for getting the rawValue and "=" for targetB as you had it.

I've also found a digital download copy of Javascript: the definitive guide

available on amazon; thanks for the recommendation.

Your assistance is really appreciated: hopefully some day we may be able to

return the favor (we're noob computer folks, but not too bad Australasian

lawyers - and always happy to return a favor). In the interim if there is a

donation button anywhere in this forum (or wherever) we'd be delighted to

shout you a beer.......

Thanks once again....

Regards

Greg

Avatar

Level 10

No problem Greg, glad you got it working.

In the cold light of day, I would add that the book is heavy; it goes back to first principles and give an insight as to why Javascript is the way it is. The sections dealing with core javascript are what's relevant, but note that the flavour of javascript in LC is subtly different.

There are free guides on the Adobe web site which cover Acrobat and LC:

http://www.adobe.com/go/learn_lc_scriptingBasics

http://www.adobe.com/go/learn_lc_scriptingReference

http://www.adobe.com/go/learn_lc_formCalc

http://www.adobe.com/devnet/livecycle/articles/Adobe_XML_Form_Object_Model_Reference.pdf

http://www.adobe.com/devnet/acrobat/pdfs/lc_migrating_acrobat_xmlform.pdf

And a very handy resource: http://partners.adobe.com/public/developer/en/tips/CalcScripts.pdf

JP Terry's book on LC Forms is very good and we use www.pdfscripting (which is a subscription service).

Good luck

Niall

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----