Expand my Community achievements bar.

SOLVED

IF expression within Subform

Avatar

Level 1

Dear All,

I just started using LiveCycle a couple of days ago. Spent a tremendous amount of time reading litteratures and several websites.

I am stuck on something that apparently is extremely simple:

I have a form with 2 subforms. In my 2nd subform, I have 2 tables and a bunch of fields (address fields mainly).

The 1st table is products and quantities.

The 2nd table is subtotal, taxes and total.

I wanted to use the IF expression to condition my taxes:

IF the value if the cell called "ShippingState " = CA, then I apply taxes

else no taxes.

Simple enough.

I thought this would work:

if ( form1.#subform[2].ShippingState = "CA" ) then Subtotal * 8 / 100
else 0
endif

I doesn't work with or without the " " aroudn the value of ShippingState.

There is no typos in the names of the cells.

Subtotal is the adjacent cell to the one I added this expression

Could anyone explain what I am doing wrong? It would be greatly appreciated.

All the bes,

Damien

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Damien,

There are a few things to watch out for:

  • First I see that you are naming objects on the form, like 'ShippingState' field, however it looks like you are not naming subforms '#subform[2]'. This is not a good idea, as it makes it more difficult to reference objects in the form. I would recommend that you name objects based on their purpose, as soon as you drag them onto the form. Also watch out for (and avoid) naming objects with reserved words, like 'h', 'exit', 'and', etc. For this example lets says the subform was called 'shippingInfo'
  • Next when assigning a value to an object you use a single equals symbol '=', but when testing against a condition you use a double equals sign '=='. There is a third situation when testing that the object is identical to a condition, where you use three equal signs '==='. But for most situations '==' will do in the if statement.
  • The syntax is FormCalc so just make sure that you have set the language in the Script Editor to FormCalc.
  • I appreciate that FormCalc allows you to just write the calculation and it knows to apply it to the object. I have a slight aversion to this and prefer to be specific by using '$ = ...'. So if I was writing it I would go:

if (shippingInfo.ShippingState == "CA") then

     $ = Subtotal * 8 / 100

else

     $ = 0

endif

I suspect that the ShippingState and the Subtotal are in different subform, but in the same 'form1', therefore you should not need 'form1' in the reference.

Hope that helps,

Niall

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi Damien,

There are a few things to watch out for:

  • First I see that you are naming objects on the form, like 'ShippingState' field, however it looks like you are not naming subforms '#subform[2]'. This is not a good idea, as it makes it more difficult to reference objects in the form. I would recommend that you name objects based on their purpose, as soon as you drag them onto the form. Also watch out for (and avoid) naming objects with reserved words, like 'h', 'exit', 'and', etc. For this example lets says the subform was called 'shippingInfo'
  • Next when assigning a value to an object you use a single equals symbol '=', but when testing against a condition you use a double equals sign '=='. There is a third situation when testing that the object is identical to a condition, where you use three equal signs '==='. But for most situations '==' will do in the if statement.
  • The syntax is FormCalc so just make sure that you have set the language in the Script Editor to FormCalc.
  • I appreciate that FormCalc allows you to just write the calculation and it knows to apply it to the object. I have a slight aversion to this and prefer to be specific by using '$ = ...'. So if I was writing it I would go:

if (shippingInfo.ShippingState == "CA") then

     $ = Subtotal * 8 / 100

else

     $ = 0

endif

I suspect that the ShippingState and the Subtotal are in different subform, but in the same 'form1', therefore you should not need 'form1' in the reference.

Hope that helps,

Niall

Avatar

Level 1

Niall,

Thank you for your help.

Glad to see all the information and I will definitely keep that handy.

Best regards,

Damien