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

Question

Question

Trigger Lookup Every Time A Form Loads

asked on April 4, 2018

I have a form that started via Workflow, has it's initial variables assigned to it's fields, and then is assigned to an approval task.  There is then a timer on this approval task that triggers a workflow to update the variables.  The first issue is that when the user loads the form, it still shows the original variable values from when the form was first assigned and not the latest ones assigned by the Workflow.  I understand this is due to different submission ID's and thus I started writing the appropriate variables to SQL tables and now the form fills them based on lookups.  This is also working fine with lookups but the issue now is that when the form loads, there does not seem to be a way to trigger the lookup automatically so it loads the current SQL values.  If I change the single input field to something else and then back, it does trigger the lookups and the fields do correctly update to their new values.  My goal was then to trigger a change via JavaScript but have not had any luck.  

To simplify it (as my form is filling 5 tables and 20+ fields), here is an example.  Field1 is triggering the SQL Lookups that fill Field 2 and Table1.  The form is started with the Invoke Business Process Workflow activity and Field1, Field2, and Table1 are filled with their initial values via the Set Business Process Variables Workflow activity.  This works fine to start the form, fill those fields, and assign it to the first approval step.  When the user opens the form at this first approval step, they see the values that were assigned by the Workflow activity instead of the current values if the Lookups were to run.

  • If they manually change Field1 to something else and then back, Field2 and Table1 update correctly
  • If JavaScript tries to trigger a change event on Field1, nothing happens

 

So far I've tried many variations of triggering the change event, including those below:

  • $('#q1').change();
  • $('.class input').change();
  • $('.class input).trigger('change');
  • $('#q1').trigger('change');

I've also tried changing the value to something else, triggering the change event, changing it back to it's original value, and triggering the change event.  Has anyone successfully triggered a Lookup when a form first loads based on a single line field that already has a value assigned?

0 0

Answer

SELECTED ANSWER
replied on April 5, 2018 Show version history

I've run into similar issues, and although I'm not completely sure what your real issue is (I'm newbie), it sounds as if you are having issues with the timing of a certain trigger. 

In Forms 10.2 there is a function that you can use to wait until the Lookup Rule loads, and then it does something. Here is an example.

$(document).on("onloadlookupfinished", function (event) {
     // then you do something here
});

In previous versions you can set a wait time like below. Usually a second is enough

setTimeout(function(){
       // then you do something here
}, 1000);

 

2 0
replied on April 5, 2018

I apologize but I forgot to mention that I tried the "onloadlookupfinished" function.  It still did not run the lookup and took the form from loading in 3 seconds to 45 seconds.  I also tried the timer and that just delayed the whole form from loading but still did not run the lookup event.  I am doing all of this in Forms 10.3.0.975 so I wonder if there is an issue in this version that is preventing it.

0 0
replied on April 5, 2018

If using onloadlookupfinished function delayed your javascript by 45 seconds, that means the lookup must be running and running for 45 seconds. Which is likely timeout period. It appears the lookup is timing out after 45 seconds on form load.

 

Try calling a basic stored procedure that returns a pass fail output.

1 0
replied on April 17, 2018

So I had this working fine for one customer without the "onloadlookupfinished" and copied the exact same code to another and had to use "onloadlookupfinished" to get it to work.  I am guessing it is just the timing where the lookups load much quicker at one than the other as they are both running the same version of LF & Forms and I am testing in the same browser.  Either way, thanks for everyone's help on this as "onloadlookupfinished" saved the day.

0 0

Replies

replied on April 4, 2018

Oddly enough I have been having the opposite problem. In Forms 10.2.1, when I add a lookup, it triggers on form load. I am sure of this because I have to add code into my stored procedures to see if the values are blank and ignore the lookup.

Surprised to hear that the following code doesn't trigger a lookup though, that would be my next recommendation. That should be no different than a user making a change to the field.

  • $('.class input').change();
0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.