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

Question

Question

Forms on lookup start

asked on April 12, 2019

Is there any way to know when a lookup starts? 

There are 2 reasons for this, one is to let the user know a lookup is running for long lookups, the other is to unbind on change events so that values populated by a lookup do not trigger executions meant for values changed by a human.

I tried monitoring the trigger field for changes, but the lookup system halts all event calls for trigger fields, pushing them out until after lookups complete, causing the lookup to run before I even know the trigger field had been changed.

Example:

 
$('.trigger input').on('change', function() {
console.log('Trigger field just changed, lookup is going to run');
});

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

Expected Output:

Trigger field just changed, lookup is going to run

Lookup Complete

Actual Output:

Lookup Complete

Trigger field just changed, lookup is going to run

1 0

Answer

SELECTED ANSWER
replied on April 12, 2019

Yes, you can find information about the lookupstarted event in the following thread

https://answers.laserfiche.com/questions/108471/Can-we-get-a-lookups-complete-custom-event-listener-please#121241

2 0
replied on April 15, 2019

Thanks Jason! This will be perfect!

0 0
replied on April 15, 2019

The key is to use event.triggerId

That will give you the Id of the specific field that triggered the lookupstarted event so your function can do different things based on which lookup runs.

If I'm only watching for one or two, I just use an IF, but when I have several I use a switch instead.

0 0
replied on April 15, 2019

Yes, you helped me with that one before, really helpful if you have lots of lookup rules. Thanks again!

0 0

Replies

replied on April 19, 2019

These methods are half backwards and impossible to use. I have done extensive testing now. I am going to submit a support ticket with an example form. The lookup complete method runs before the lookup started method, and both methods run after the lookup is complete.

This code produces this output

$(document).ready(function() {

  //Track when the table values change
  $('li.table').on('change','.qty input,.seq input,.asm input,.job input', function() {
    
      console.log('lookup table values changed');     
          
  	});
  
//Track when a lookup has been started
    $(document).on("lookupstarted", function (event) {
        console.log('lookup starting');  

  });
  
//Track when a lookup is complete
  $(document).on("lookupcomplete", function (event) {
    
    console.log('lookup complete');
    
  }); 
  
  
});
  
  
  

Output:


lookup table values changed
lookup complete
lookup starting

 

1 0
replied on April 19, 2019 Show version history

I've never had a problem and I use those events on the vast majority of my forms.

Try the following:

$(document).ready(function(){  
  $(document).on('onloadlookupfinished',function(event){
    console.log('Load Lookup Finished');
  });
  
  $(document).on('lookupstarted',function(event){
    console.log('Lookup Started: ' + event.triggerId);
  });
  
  $(document).on('lookupcomplete',function(event){
    console.log('Lookup Complete: ' + event.triggerId);
  });
});

And check the results again, I get the following for example

My guess is that you're going to see multiple field IDs rather than the same field triggering the events in the wrong order.

0 0
replied on April 19, 2019

Just tested, I just have one lookup rule and I am using chrome. This is my output replacing my javascript with yours.

Lookup Complete: Field56
Lookup Started: Field56

What the heck?

0 0
replied on April 19, 2019

I can't say I've ever seen that before. What version of Forms are you running?

Is the lookup actually returning any results?

0 0
replied on April 19, 2019

10.3.1.690

Yes it is populating the table, and because of the on change function I use I can see when it actually runs. It runs before the lookup complete which is accurate but also before lookup started, and lookup complete runs before lookup started.

0 0
replied on April 19, 2019 Show version history

Do you have the change event enabled right now?

If so, I'd recommend trying with only the code I provided enabled to rule out the possibility that some other JavaScript code is interfering.

0 0
replied on April 19, 2019

Yes, the gif from above is testing with only your code. So it is not logging on changes.

0 0
replied on April 19, 2019 Show version history

Try adding a timestamp, it almost looks like they're firing at the same time, but a timestamp will help determine the actual difference, however brief.

$(document).ready(function(){  
  $(document).on('lookupstarted',function(event){
    var d = Date.now().toString();
    console.log('Lookup Started: ' + event.triggerId + ' ' + d);
  });
  
  $(document).on('lookupcomplete',function(event){
    var d = Date.now().toString();
    console.log('Lookup Complete: ' + event.triggerId + ' ' + d);
  });
});

 

0 0
replied on April 30, 2019

Support said they are getting the same result, lookupstarted is not executed until after lookupcomplete is executed, which are both after the lookup is done populating all values.

Thankfully I had a read only field, and I found that lookup populate fields in the order you place them in within the lookup definition. So I was able to put the read-only field first and then monitor for changes to this field, which MUST be a lookup starting since no one else can change this field.

You can then set a bool to show that the lookup has started and you caught it, following up by setting the bool to false when the lookup complete is executed.

0 0
replied on May 17, 2019

Just to provide an update, I happened to run into the same issue and narrowed it down a bit; this only seems to occur with multi-condition lookups.

If all of my lookups have one condition, it works as expected, but if the source field is part of a multi-condition lookup, then the events fire out of order.

When I disabled the multi-condition lookup, the other lookups connected to that same field started firing the events in the correct order.

0 0
replied on May 17, 2019

Got it, I can confirm that I am using more than one field in the lookup condition.

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

Sign in to reply to this post.