- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 04:59 AM
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 !!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 02:26 AM
@Rahul84 Have you tried this? if yes then please close the thread by marking all correct answers
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 04:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 02:07 AM
Hello @jaheerhattiwale ,
Need help in capturing the API response in one of the catalog form field which a drop down option field.
Below is the API response , we are getting , I need to fetch the name value (underlined with blue) and add that to drop down field as a option.
In response we can get any number of records each will have name parameter.
Please help in the below code which you have provided .
for (var i = 0; i < responseBody.length; i++) {
g_form.addOption("drop_down field name", responseBody[i].value, responseBody[i].label, i);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 02:17 AM
@Rahul84 First you need to parse the response body you received. The add for loop.
Do this in client script
var parsedResponseBody = JSON.parse(<RESPONSE FROM API HERE>);
var options = parsedResponseBody.result;
for (var i = 0; i < options.length; i++) {
g_form.addOption("drop_down field name", options[i].name, options[i].name, i);
}
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 02:28 AM
Is the below line mentioned in for loop correct ? options[i].name is repeated two times
g_form.addOption("drop_down field name", options[i].name, options[i].name, i);
earlier you have suggested the below line.
g_form.addOption("<DROP DOWN FIELD NAME HERE>", responseBody[i].value, responseBody[i].label, i);
Also solution is not working , values are not coming in the field as drop down.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 02:32 AM
@Rahul84 There is no label there right so i thought choice label and value will be same
ServiceNow Community Rising Star, Class of 2023