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

@jaheerhattiwale : I have some doubts. Can you pls clear.

[] For the instance property creation. You are suggesting to add the servicenow prod url in the value field but my REST API is not having the servicenow url. It has some other url value something like this - https://store-api-test.com/blablablablabblaaa
and as per your script complete endpoint will be as below -

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

 

[] Also you are suggesting to add servicenow production value in the property , what about for non-prod ones?

[] for the authentication part. Username and password not stored in the servicenow instance.

We have just hard coded the values in the script to set basic auth

 

what best we can do to run the same script for PROD and NON-PROD instances to set the non-prod & PROD API and Basic auth ?

@Rahul84 Ok got it.

 

In Prod instance name property add "store-api-test.com"

in user id and password properties add the credentials of "store-api-test.com" this site.

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

@jaheerhattiwale : ok, also how we are catering the non-prod API execution becoz we are only adding the prod api url in the property. can you suggest how we are going to cater the non-prod execution with the same script.

Also for the user name and password.

we can directly pass the username and password (hardcoded values) in the property value field ? will this work if we don't have those records in the servicenow instance.?

Rahul84_0-1671115425906.png

Rahul84_1-1671115484274.png

 

 

 

@Rahul84 You just need to change the property values with subprod instance name credentials.

 

Don't change code at all just update the properties 

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

@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