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

Question

Question

Trigger Lookup Rule again using JavaScript

asked on February 9, 2020

Hi, if we have a lookup rule that fills in a list of data but the rule does not actually have any condition, is there any way to trigger this rule again using JavaScript? We find that the field values in auto-suggest are gone after the lookup has completed, for example:

 

1. Rule to fill field A and field B, no condition as it grabs all value in database

2. User select field A and lookup fills field B

3. User can also do this other way round, user select field B and lookup fills field A

4. But if the user makes the mistake and clears both fields, the previously populated value in field A and B are gone, and we have to somehow trigger the rule in step 1 again to fill the value.

 

Thanks

0 0

Replies

replied on February 11, 2020

Hi Wai,

Here are two ways you could go about this:

  1. You could create a stored procedure, and give it a blank input variable which is not actually used for anything. This would allow you to refresh the lookup by using JavaScript/jQuery and calling .change() on a blank field that you use for this input variable.
  2. You could do this by having two additional hidden fields that are the targets of steps 2 and 3. So, have fields A1 and B1 that are filled at the beginning from the initial lookup rule. Then, if text is entered into A1, hide B1, show field B2, and fill B2 with the lookup rule in step 2. Otherwise, if B1 is not empty then do the reverse with A1 and A2 for step 3.
    That way, if they make a mistake by filling in A1 first (which would then show only A1 and B2), they can erase that and it will show only A1 and B1 with their original lookup values. If these variables are required later in the process, then you could have two more fields A3 and B3 that automatically fills with the right one through either JavaScript or field calculations.

Hope this helped.

0 0
replied on February 11, 2020

Hi Jim,

 

Thanks for your advice, I think the first suggestion with the stored procedure would be a better method. However I have another question, would the first method work if the two fields are in a table? As we tried something similar by triggering .change() on a field for step 1, and the populated values was wiping the data on field A and B on the previous row, so far we haven't found a way to prevent this from happening.

 

Thanks

0 0
replied on February 12, 2020

For a lookup rule that populates the whole table's values, it will replace it for every row. However, when a lookup rule's input parameter is a table's column, it treats it as a per-row lookup rule. You can verify this since the "as new rows" checkbox will be visible but greyed out.

So, it should work if you put the dummy field as a column the table, and then trigger the .change() on only the one on the row that you want changed. It should also automatically run the lookup rule whenever a new row is added.

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

Sign in to reply to this post.