Copy data from one Address Field to another

Copy data from one Address Field to another

Requirement

Copy one Address field to another automatically while filling out a form.

Use Case

An online e-commerce application generally would ask every customer to enter separate billing and shipping addresses. Sometimes, people have both the addresses same. We need to ensure that if the user says both are same, we copy the shipping address to the billing address.

See how it works

Steps to follow

1. Create the forms with the following details:
Form
Form Link Name
Field Type
Field Name
Field Link Name
Delivery
Delivery
Name
Name
Name
Email
Email
Email
Address
Shipping Address
Shipping_Address
Decision Box
The billing Address is the same as the Shipping Address
The_billing_Address_is_the_same_as_the_Shipping_Address
Address
Billing Address
Billing_Address

2. Create a workflow to execute on the user input of the Decision Box to toggle the display of the Billing Address field when the box is checked, and to copy the Shipping Address field to the Billing Address.

3. Click Add New Action and add the below script:
  1. if(input.The_billing_Address_is_the_same_as_the_Shipping_Address)
  2. {
  3. //Hide the Billing Address field when both are same
  4.   hide Billing_Address;
  5. //Assign the Shipping Address value to Billing Address
  6.   input.Billing_Address = input.Shipping_Address;
  7. }
  8. else
  9. {
  10. //Display the Billing Address during the toggle of the Decision Box
  11.   show Billing_Address;
  12. }

4. We shall create another workflow to execute during the successful form submission to copy the Shipping Address to Billing Address.
 
5. Click Add New Action and click Deluge Script. Add the below Deluge script for copying the addresses.
  1. //If the Decision Box is true and the Business Address is empty, copy the Shipping Address to Billing Address
  2. if(input.The_billing_Address_is_the_same_as_the_Shipping_Address && input.Billing_Address.trim() == "")
  3. {
  4.   input.Billing_Address = input.Shipping_Address;
  5. }

See how it works


Points to Note

  • We can only specify the link name of the "Address" field when assigning it a value copied from another "Address" field. In all other cases, we have to give values for its sub-fields separately, as explained in this table.
  • The working of the composite Name field is the same.
Related Links