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

Question

Question

javascript to re-execute a lookup

asked on March 21, 2019

We have a form that fills a DCO# field from the prior process.  We have a table that populates a 'New' and 'Current' field based off a lookup from the DCO# value carried from the past process.

Currently, the lookup seems to run BEFORE the field has the data loaded and thus the results are blank. 

To get the 'New' and 'Current' fields to populate from the lookup, we have to manually change the value from the DCO # field  and type it in again to get the lookup to display results.

question1.jpg
question2.jpg
question1.jpg (99.07 KB)
question2.jpg (81.47 KB)
0 0

Answer

SELECTED ANSWER
replied on March 21, 2019

Please keep in mind that lookupcomplete is a broad event. You should also log the event.triggerId to see exactly which field is calling the event.

I have a form that refreshes data and when I trigger the change event it re-runs the lookup with updated data so I know it can work.

In mine, I don't even refresh the value of the trigger field, I just trigger the change.

1// Refresh contact data
2$('.userAccount input').change();

 

1 0

Replies

replied on March 21, 2019

I am trying to do the same thing right now. You can log to the console to see if your lookup was triggered with this code

    $(document).on('lookupcomplete', function() {
console.log('Lookup Triggered');
});

 If I trigger a change call on the field, then it logs that the lookup was triggered. 

$('.clientName select').val($('clientName select').val()).change(); 

But the lookup never actually runs, because I can see that the latest value from the database is not showing.

If I manually touch the field, then the lookup runs. So something is inaccurate about the lookup complete trigger and it makes it difficult to troubleshoot how to best trigger a lookup with javascript.

2 0
SELECTED ANSWER
replied on March 21, 2019

Please keep in mind that lookupcomplete is a broad event. You should also log the event.triggerId to see exactly which field is calling the event.

I have a form that refreshes data and when I trigger the change event it re-runs the lookup with updated data so I know it can work.

In mine, I don't even refresh the value of the trigger field, I just trigger the change.

1// Refresh contact data
2$('.userAccount input').change();

 

1 0
replied on March 21, 2019

Ah, that triggerId helps isolate which rules are running and which are not.

I had a lookup that pulled an ID which triggers another lookup. Apparently if the lookup pulls the same value, it doesn't continue the chain of lookups.

So I just triggered the ID field directly, using your method and it works! Thanks!

0 0
replied on March 21, 2019 Show version history

It worked after we inserted a 1 second  time delay to your code.

Thanks!

0 0
replied on March 21, 2019

Make sure the .change() method is called inside of a function called after the form loaded and ready, otherwise it will execute before the fields even exist. That might be your issue. IE

$(document).on('ready', function() {

});

 

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

Sign in to reply to this post.