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

Question

Question

Fill an address block with data from external table

asked on September 17, 2021

I see two answers to this question from 2017 and 2019 saying it is not supported. Is it not possible to do this with JavaScript? If it is, I would appreciate if somebody could share their code. (Has it been submitted as a feature request to support through Lookup Rules?) Thanks!

Our scenario: We are using a form with new clients to collect profile information. During the lead process we may have already collected some of this information. We want to pre-fill the form with data already on hand (in crm) so we are not asking for the same info a second time.

0 0

Answer

SELECTED ANSWER
replied on September 20, 2021 Show version history

Griff,

Populating an address block from a lookup is not natively supported but it is doable using javascript, albeit a bit cumbersome.

Typically I populate a hidden single line field with a value from a SQL view using a lookup.  The SQL view returns the address block values separated by a pipe character ('|'). A typical lookup for an address will return something like this; 'Address line 1|Address line 2|City|State|Zip|Country'.  I then have a javascript onchange event triggered when the hidden address field changes.  That onchange event splits the hidden address field value on the pipe character and then assigns each element of the array to the specific address block fields.

In this example the hidden address field has a class name of 'hiddenAddress' and the address block has a 'q' number of 1.

Here is a screen snip of the form after the hidden address field has been populated by the SQL view;

Here is the javascript;

$(document).ready (function () {

  //
  // If the hidden address field changes from a lookup then retrieve
  // the value, split it on the pipe character to get an array, then
  // assign the array elements to the address fields.  If the lookup 
  // returns an empty value then clear out the address fields...
  //
  $('.hiddenAddress input').on('change', function() {
  	var streetAddr = $('.hiddenAddress input').val().split('|');
    if (streetAddr.length == 6) {
      $('#Field1_DSG0').val(streetAddr[0]);    	
      $('#Field1_DSG1').val(streetAddr[1]);    	
      $('#Field1_DSG2').val(streetAddr[2]);
      $('#Field1_DSG3').val(streetAddr[3]);
      $('#Field1_DSG4').val(streetAddr[4]);
      $('#Field1_DSG5').val(streetAddr[5]);
    } else {
      $('#Field1_DSG0').val('');    	
      $('#Field1_DSG1').val('');    	
      $('#Field1_DSG2').val('');
      $('#Field1_DSG3').val('');
      $('#Field1_DSG4').val('');
      $('#Field1_DSG5').val('');
    }
  });

});

If there is more than one address block in a form (which there usually is) I move the address field  value assignment to its own function and call that function from the document lookupcomplete event.  The function accepts the hidden field value and an array of the address block fields as parameters and the assignment happens there.

2 0

Replies

replied on September 20, 2021

Cliff- extremely helpful. Thank you very much!

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

Sign in to reply to this post.