Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Non-Nested ifs

Avatar

Level 2

My noobish understanding is that "if" statements are excuted if a boolean true occurs, and if it doesn't occur the script continues after the closing curly bracket.

The script below is from a numeric field and is fired by the calculate event, so it runs repeatedly. I'm wondering why the "hello world" part doesn't get excuted every time around. Instead, it always waits for a boolean true from  the second "if".

if (ExpenseClaim.Page2.DistanceRecord.TableKM.Row1.Locations.Location1.rawValue.length != 0 && ExpenseClaim.Page2.DistanceRecord.TableKM.Row1.Locations.Location2.rawValue.length != 0)

{

blah blah blah

}

if  (ExpenseClaim.Page2.DistanceRecord.TableKM.Row1.Locations.Location2.rawValue.length != 0 &&  ExpenseClaim.Page2.DistanceRecord.TableKM.Row1.Locations.Location3.rawValue.length != 0)

{

blah blah blah

}

xfa.host.messageBox("Hello World");

if  (ExpenseClaim.Page2.DistanceRecord.TableKM.Row1.Locations.Location3.rawValue.length != 0 && ExpenseClaim.Page2.DistanceRecord.TableKM.Row1.Locations.Location4.rawValue.length != 0)

{

blah blah blah

}

if  (ExpenseClaim.Page2.DistanceRecord.TableKM.Row1.Locations.Location4.rawValue.length != 0 &&  ExpenseClaim.Page2.DistanceRecord.TableKM.Row1.Locations.Location5.rawValue.length != 0)

{

blah blah blah

}

And if I move the "hello world" part to below the third "if", it waits for that. What's going on here?

Thanks.

5 Replies

Avatar

Level 10

Hi,

Sometimes code in the calculate event doesn't report all the run time errors, maybe try putting the code in the click event of a button as a test and see if it works.  Are all you locationX fields text fields, as if they are numeric they wont have a length property.

Bruce

Avatar

Level 2

Helpful suggestions, thanks.

I threw the script into a button and it still behaves the same way. However, when I open the document in Acrobat Pro (which actually has a debugger! Imagine!), the script halts (but doesn't throw an exception)  at the next unexectuted "if", so I think you might be onto something with your idea on the LocationX property.

That field is a pull down with text items, so I would think .length would be OK. I'll play around with other tests.

Thanks.

Avatar

Level 2

Solved.

You were right. The script chokes on the .length property for these objects. But if I snip it off and simply test the rawValue it's all good. Suits me fine.

Thanks.

Avatar

Level 10

Hi,

In Acrobat make sure you have "When Exception Thrown" set to break, under edit ... preferences ... JavaScript, if you aren't getting the exception reported (you might need to restart Acrobat for it to take effect).  The default is ignore ... just like in a browser.

Bruce

Avatar

Level 2

Yes, it was set to this.

Funny thing, the script halts with a yellow arrow pointing at the "if" line of code, but no exception is reported.

Oh well, it's working now. Now I need to move on to my next goal....making it work with multiple table rows.

I see a bunch of "resolvenode" in my future....