Populate Catalog Item Variable with REST Call with Immediate Results Displayed

ctsmith
Mega Sage

I have a REST integration that pulls in application names from a 3rd party into a custom SN table when the form loads using an onLoad catalog client script that references a script include. There is a variable on the catalog item that is linked to the names on the custom table so a user can pick from the list of names brought in from the 3rd party API.

The problem I'm having is that the variable only shows the results from the last call to the 3rd party application.   For example, User 1 opens the form and the call brings in applications A, B, and C from the integration that performs the REST integration function onLoad.   This user tries to select from the list in the variable, and it's empty.

User 2 opens the form and the call brings in applications D and E.   User 2 tries to select an app from the variable list, and User 2 only sees A, B, and C from User 1's call, but not D and E from User 2's call.

And so on...   it will always be one behind.

Thoughts?


Thanks!

Chris

21 REPLIES 21

The table does get populated.   I'm not sure how often the information will change when this is moved to our PROD environment, but this REST call is made every time a user opens the form.



Yeah... I'm thinking about populating a normal select box instead of a table...   Good point.


Actually, I tried to do a regular select box option before, and the issue was the same.   It wrote the values to the question properly, but, again, nothing showed up on the form view until I entered the form a second time.   The values are not there in time for the form when it loads.   Is there a way to "refresh" a variable after it loads, like with an onChange script?


bbarber9
Giga Expert

You could send a second rest call if you wanted, but what I would do is make the variable read only until you have all the information you need, then make it editable after that. You might need to do some debugging and see what your AJAX is returning and make sure it is giving you the information you expect the first time around.


I'm not sure what setting it to read only would do to prevent the variable from loading on the form before the values are populated on the table that the variable references.   None of the Ajax async or setTimer methods seem to be doing anything to pause the form to load.



When I first set this up, I had it logging all the values, so the call is bringing over exactly what I want (after I parse out the values I don't need).   The call is working properly, it's just the form loads before it's done writing to the table for the user to select from..



Best,


Chris


may I suggest trying something? create another field maybe true/false(can be whatever type you want). you can hide this field it is for functionality only. run a synchronous call then once the call is done and the table has been updated change the value of your new field...



then on your lookup select field go to attributes and add ref_qual_elements=u_new_field_name   try this solution. ref_qual_elements is a cool attribute it basically tells your reference to re-query if a field changes value. I haven't tested it in this exact scenario, but I think it should work.