You are viewing limited content. For full access, please sign in.

Question

Question

Modern form - reference to address collection in javascript

asked on July 14

Hello,

 

How do I reference to a field in the address collection to set a value, say from Lookups?

     LFForm.setFieldValues(<FullAddress.Address1>,"12345 My Street")

 

Thanks

0 0

Replies

replied on July 14

Are you wanting to take a value from a single line field that has a lookup rule and move it to the Advanced Address fields?

0 0
replied on July 14

That's correct.  If there's a way to assign Lookup field value directly to the Advanced Address collection, that's even better. 

 

Thanks

0 0
replied on July 14

var ADDRESS_FIELD_ID = 11;  --The Field ID of the target Address collection field on this form.

// Map each Address subfield to the Variable Name of the single-line field

var SOURCE_FIELDS = {
  address1: "Street Address",       // -> Street Address
  address2: "Address2",     // -> Address Line 2
  city:     "City",         // -> City
  province: "state",        // -> State/Province/Region
  zipcode:  "zip"           // -> Postal/Zip Code
  // country: "Country",    // -> Country (uncomment and set variable name if used)
};

Object.keys(SOURCE_FIELDS).forEach(function (subField) {
  var sourceVariable = SOURCE_FIELDS[subField];

  LFForm.onFieldChange(function () {
    var value = LFForm.getFieldValues({ variableName: sourceVariable });
    var update = {};
    update[subField] = value;

    LFForm.setFieldValues({ fieldId: ADDRESS_FIELD_ID }, update);
  }, { variableName: sourceVariable });
});

Use the Field ID in your form for the Address Block and then make sure your variable names of the single line fields used to lookup the data match the source field list that matches the names of the labels.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.