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

Question

Question

Forms Lookup Not Triggering

asked on March 16, 2023 Show version history

I am stuck on a script and am hoping someone can help.  Strangely, my code is not working on a new form that I'm creating but has been working on a previous form.  It should be a simple copy and paste but for whatever reason, it has been unsuccessful.  Here's the setup:

 

Field 1 is populated by a lookup table.  That is coming through successfully.  I have a javascript that strips the domain name from Field 1 and populates Field 2.  That is also working successfully.  I have a lookup rule configured to query a SQL table using Field 2 and return a value to Field 3.  That piece is not working.  I have my code embedded in Document Ready.  If I manually change the value in Field 2, the lookup runs which confirms the data exist and connection is successful.

 

$(document).ready(function() {

  $('#Field2').val(document.getElementById('Field1').value.replace('DOMAINNAME\\',''));

    $('#Field2').trigger('change');

})

0 0

Replies

replied on March 16, 2023

Hi Blia,

 

With your description, I cannot even make the value change to Field2 work, this is because the code under $(document).ready() is executed before lookup returns result (To verify this, you can add some console.log() sentence is your code and check in devtools). If Field1 is returned by lookup rule, then Field2 should not be updated successfully. I just go ahead and use another way to make your scenario work:

$(document).ready(function() {
//listen to the onloadlookupfinished event
  $(document).on('onloadlookupfinished', function(){
    console.log('onloadlookupfinished');
      $('#Field2').val(document.getElementById('Field1').value.replace('DOMAINNAME\\',''));
        $('#Field2').trigger('change');
  });
});

 

0 0
replied on March 17, 2023

Hi Zhiyong, 

 

I'm sorry, I should have specified that Field 1 is populated by the out of the Forms box "_currentuser" variable.  I'm not sure if that makes a difference in how the page loads but that might explain how the value change to Field 2 works inside document ready.  With that in mind, would have any thoughts to resolve this?

 

Thanks,

Blia

0 0
replied on March 19, 2023

well, if Field1 is using the "_currentuser" variable, then your code works in my test. When you preview your form, can you check in DevTools and find the lookup api, see what is the request and response?

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

Sign in to reply to this post.