Skip to main content

๐Ÿก Copy Student's Address to Parent

Suppose you have a form with a student's address and a parent's address. You might wish to allow the student to check a box to duplicate the address. โœ…

These approaches may not be necessary! Address blocks now have a built-in "Allow Copy From" option that solves most use cases.

Method 1: Using Individual Fields

Using this method, the relationship's address block will disappear when the student selects to copy the address. The address will be copied to the relationship record via hidden fields that use calculation formulas.

Create the following fields with the following settings:

  • ย  ย  Student's street address block (sys:address)
  • ย  ย  A checkbox like "My address is also my parent's address"
  • ย  ย  Relationship's street address block (sys:relationship:address)
    • Set logic on this field to disable it when the checkbox is checked. This is the one students will use if their parent's address is different.
  • ย  ย  Section break
    • Set logic on this break to disable it when the checkbox is not checked. This is the one that will copy.
  • ย  ย  Text fields for each element of the relationship's address
    • Set all fields to 'Hidden (accessible through script)' and add a calculation formula.
    • Use the calculation formulas in the table below โฌ
  • ย  ย  End section break
Export Key ย Calculation Formula
sys:relationship:country @sys:address.country
sys:relationship:street @sys:address.street
sys:relationship:city @sys:address.city
sys:relationship:region @sys:address.region
sys:relationship:postal @sys:address.postal

Method 2: Copying an Entire Address Block

This script will attach calculation formulas to each element of your destination address block. In this example, we're assuming our source address block is sys:address and our destination address block is sys:relationship:address.

Double-check your export keys. Your address block may be named sys:address_block.

This method is harder to understand but allows you to keep using nice-looking address blocks.

var source_address = "sys:address"
var destination_address = "sys:relationship:address"

var sa2 = "@" + source_address
var da2 = "[data-export='" + destination_address + "']"
$(da2 + " select[id$='_country']").attr("data-formula", sa2 + ".country");
$(da2 + " textarea[id$='_street']").attr("data-formula", sa2 + ".street");
$(da2 + " input[id$='_city']").attr("data-formula", sa2 + ".city");
$(da2 + " select[id$='_region']").attr("data-formula", sa2 + ".region");
$(da2 + " input[id$='_postal']").attr("data-formula", sa2 + ".postal");
Form.initializeCalculatedFields();