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.

Shipping address = Billing address [auto-populate]

Avatar

Level 1

There may be more graceful ways to code this (I'm new to formcalc). If anyone has a better way please chime in. I'm posting it because I didn't find any resources on it and thought it might save someone else some time.


Billing Address field names:

bill_addr

bill_city

bill_state

bill_zip

Check box name:

same_addr

Check box: 

               on/off

Check box binding:

On = 1

Off = 0

Mailing Address field names:

mail_addr

mail_city

mail_state

mail_zip

Mailing Address field codes:

mail_addr:

if (same_addr > 0) then (bill_addr) else $.rawValue = $.rawValue endif

mail_city:

if (same_addr > 0) then (bill_city) else $.rawValue = $.rawValue endif

mail_state:

if (same_addr > 0) then (bill_state) else $.rawValue = $.rawValue endif

mail_zip:

if (same_addr > 0) then (bill_zip) else $.rawValue = $.rawValue endif

explanation -- if the “same_addr” box is checked it’s “on” with a value equal to 1 (greater than zero) then the billing field will populate with data from its corresponding mailing field, or the “else” statement means “it is what it is”

Let me know if this helps.

LK

3 Replies

Avatar

Level 10

You can definitely streamline things so it's easier to maintain.

I'd put all the code in one if statement on the change event of the checkbox:

if ($.rawValue==1) then
bill_addr.rawValue = mail_addr.rawValue
bill_city.rawValue = mail_city.rawValue
bill_state.rawValue = mail_state.rawValue
bill_zip.rawValue = mail_zip.rawValue
endif

I don't think I'd bother with the else statements setting the rawValue - if the billing address is the same people will click the button, if it's not the same they'll fill in the info.

Depending on what your form looks like you could also set it up with a hidden subform for the billing info if needed - something along the lines of a checkbox that says "Enter Separate Billing Address?" and then:

if ($.rawValue==1) then

subformBillingAddress.presence = "visible"

else

subformBillingAddress.presence = "invisible"

endif

Avatar

Level 1

This is a belated thank you for taking the time to enter a better solution. I truly appreciate it, and I've applied the concept to other projects, making them more efficient too!