API call through Onload of a catalog form

Rahul84
Tera Contributor

Hi Developers/ @Ankur Bawiskar 

This is related to one of the tricky requirement which I need to build.

I need to call an API on the load of a catalog form and the response I need to store in one of the catalog form field which is a drop down options field.

Please let me know how I can achieve this type of requirement.

Step by Step explanation would be helpful and also a type of sample code.

Thanks in Advance !!

1 ACCEPTED SOLUTION

@Rahul84 Have you tried this? if yes then please close the thread by marking all correct answers

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

46 REPLIES 46

@Rahul84 

Create 3 new system properties

1. Production instance name

2. Integration User Name

3. Integration User Password

 

Then in the script get the values from system property and add them.

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@jaheerhattiwale  : can you help with one of the scenario for the enviroment thing only. I will replicate the same for credentails as well.

Please guide to have the sys_property for environment and usage in the script.

@Rahul84 

Create the properties in the sys_properties table.

 

then update script as below

restmessage.setEndpoint("https://"+gs.getProperty("<PROD INST NAME PROPERTY NAME HERE>")+"/<REMAINING URL HERE>");

 

restmessage.setBasicAuth(gs.getProperty("<USER ID PROPERTY NAME HERE>"), gs.getProperty("<USER PASSWORD PROPERTY NAME HERE>"));

 

Please mark all answers on this question.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@jaheerhattiwale :

and in the properties , what exactly we need to give like if I will create the property for instance.

type will be string ? and in value what should i give ? the servicenow instance url for dev and prod with comma seperated ? or the API url for dev and prod ?

 

Rahul84_0-1671112915307.png

 

 

@Rahul84 Provide the name that you have to add in getProperty() function.

Keep prod instance name property string type and in value add prod instance name

Keep user name property also string type and add the prod integration user name to it

Keep password property as password2 type and add prod integration user password

 

You must have a user account created on the prod instance for this.

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023