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 Yes that code should work but

 

if you need user name of logged in user then use below line

gs.getUser().getName();

 

If you you want user sys_id then user any one of below 2 lines

gs.getUser().getID();

OR

gs.getUserID()

 

Please mark as correct answer if this solves your issue.

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

@jaheerhattiwale , I need to pass the userid of the user as the query paramenter in the API url.

like username=apkotha &action=add&tag=abcd

Full name as APARNA KOTHA , user id - apkotha ( combination of first name and last name).

I need to fetch the user id of the logged in user/who is loading the catalog form and need to pass that in the API url.

user id - stores in sys_user table.

Please help how we can achieve this ?

 

@Rahul84 Then use below line 

 

gs.getUser().getName();

 

Please mark as correct answer if this solves your issue.

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

Thank you for helping me and replying the queries. I am trying your solution provided.

Will let you know further queries and the result.

Please keep guiding me.

Thanks a lot.

 

@Rahul84 Did you try this?

 

Can you please mark all answers on this question as correct answers. If you are recent answer then at least mark the older answers as correct answers.

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