The CreatorCon Call for Content is officially open! Get started here.

Connect Script to UI component

NatG
Tera Contributor

Hi all.

 

Completely new to ServiceNow and Scripting.

The task is to get data from an external API and show the result.  I found this example, but not sure how to attach that onChange script.  I assume those 2 select fields has to be done in UI Builder. Managed somehow (not sure if correct or not) to set the Field select to display "common" and "official" values. Then stuck... : (

 

Please, help.

Thank you in advance.

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Could you take a step back and describe the problem you need to solve? This specific script looks like it would run in a catalog client script, which would not be compatible with UIB. We need to know things like:

  1. What kind of data are you trying to pull
  2. What triggers the integration to kick off? A save, page load, button, value changing?
  3. Can you do the integration piece with integrationhub?
  4. What do you need to do with the results?

NatG
Tera Contributor

Hi Brad.

Thank you for trying to help. 

Stepping back:  i need to show how to connect external data to ServiceNow via, let's say API. 

Ideally it would be a catalog item question (example: which country are you from) and the values to that dropdown would be populated based on API response.  In original post i have attached the screenshot of one of the samples posted in this forum few years back, but do not have enough knowledge to accomplish that. 

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Ok. If it's a catalog use case then I would take UI Builder out of the equation here as it'll probably be surfaced through a Service Portal rather than a UIB experience. Generally you'd want to handle integrations through Integration Hub, but if it has to be client side you'll have to do it through a client script like the one you showed. Doing a client side integration use case like that is probably going to involve a good bit of scripting using the GlideForm API.

NatG
Tera Contributor

Hi Brad.

Appreciate your reply.  Tried few things and made some very modest progress... I have created Catalog Item with 2 select fields. Created Catalog Client Script (OnChange) as per screenshot attached in the first post and applied it to the "field' value. What i see now when testing is an attempt to pull the list, but it looks like this (see file attached).  Any idea what can cause that?  I feel i am getting closer to the solution, but not yet.   Any advise, please.