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
‎08-01-2017 09:08 AM
Allow me to clarify. What I'm talking about is the method where you do not use a table to display the values.
First, in your AJAX script include you write a method that does the REST call and parses the results to something you will need on the client side. For me i make items with a display value and an actual value because that is similar to a select box on the client side. Then I return that information to the client. This information is never stored in a table, I just pass it through.
Second, on the client side, I make a client script that calls that AJAX method and gives me back items with a display value and actual value. I use the g_form API to add options to my select box. When I talked about marking a field as read only. I meant make it read-only until we have the box populated. This helps indicate to the user that the information is not ready yet. I wouldn't recommend doing a synchronous call to your GlideAJAX because it will lock up the client until it returns.
Does that make sense?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 09:57 AM
Welp, I'm an idiot. I spent way too much time on this.
I don't know why, but switching over the variable type to just plain ol' reference instead of lookup select box did the trick.
I thank you all so much for taking the time to help me out on this.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2020 08:08 AM
Hi
1. I have a REST API query that does a Get list of network names (they're really just IP addresses) from a 3rd party application.
2. The results are turned in a JSON format so I want to only grab the network names, specifically.
3. Once those names are parsed or groomed, then I want to be able to reference the results inside a catalog item variable like a reference variable or lookup select box variable.
Any information you can share, I would very much appreciate it. Thanks in advance!
Best regards,
Harriet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 01:31 PM
If I were to do this now... I'd probably have the integration pull in new values in a scheduled job since the integration I was working on didn't get updated a lot. But I want to say the ajax call did end up building the variable list correctly.
I used a custom table at the time to store the update values (when custom tables were free), but now I'd probably just update it in the sys_choice table with an onLoad script on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 01:39 PM
Hi
That's exactly what I am looking for - have the integration pull in new values in a scheduled job.
I need help how to get it set up. Where do I begin? How would you break it down? Would it be something like:
1. Place the REST API script in the onLoad script of the catalog item
2. Have the values stored in the sys_choice table (how do you do this?)
3. Reference the sys_choice table from reference variable of the catalog item
4. Schedule a job to update the integration (how do you do this?)
I'm fairly new to ServiceNow - sorry for the many questions.
Thanks in advance for any assistance you can provide.
Best regards,
Harriet