Populate Catalog Item Variable with REST Call with Immediate Results Displayed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 09:13 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 09:20 AM
Can you give us some code to look at? That would make it easier to debug
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 09:25 AM
1) not sure what type of variable you are using? ie: reference/lookup select to your custom table or select box populated by script?
2) just from the sound of the behavior you may have a asynchronous integration which is always recommended, but in your particular case you may want to lean more towards a synchronous call and hide the variable until the call is complete and the table is populated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 09:39 AM
It is a lookup select box variable.
The catalog client script is:
function onLoad() {
var ga = new GlideAjax('apperianRest');
ga.addParam('sysparm_name', 'RestFun');
ga.getXML(apperianRestParse);
function apperianRestParse(response) {
}
var ga1 = new GlideAjax('apperianRest2');
ga1.addParam('sysparm_name', 'RestFun2');
//ga1.getXMLWait(ajaxResponse);
ga1.getXML(ajaxResponse);
function ajaxResponse(response) {
}
}
-------------------------
RestFun goes out, gets the token, then pulls in the app catalog and populates my custom table with the individual app names.
RestFun2 does some clean-up stuff; in case the app doesn't exist in the 3rd party Apperian catalog anymore, it removes from the SN table.
I can't get getXMLWait() to do anything... if that's the right tree to bark up?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2017 09:45 AM
Sounds like your rest call is returning before the table gets populated. How often does the information that you are pulling from REST change? If it isn't super dynamic then perhaps you could schedule a sync every so often. Another option might be to forego the table population if you only need it for this catalog item and just parse the response in your AJAX script include. You could use the response from your AJAX to populate a normal select box instead.