How to Populate JSON values coming from Rest API on the Catalog form variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 01:28 AM
How to Populate JSON values coming from Rest API on the Catalog form variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 07:44 PM
Hi @basavakiran ,
How about checking this page of describing JSON parser step?
I hope that you want to do on Flow..
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 08:59 PM
Hello @basavakiran ,
This appears to be a straightforward scenario. You can utilize a Script Include to call the API, and in your Client Script, invoke the Script Include to fetch the data. Once retrieved, you can use setValue
to populate the variables on your form. Does this align with what you're looking for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 09:17 PM
Hi @basavakiran ,
Follow below steps to so.
- Create a REST Message
- Create one script include and use below function. Make the Script Include client-callable.
getAPIData: function () {
try {
// Replace with your REST Message name
var restMessage = new sn_ws.RESTMessageV2('REST_Message_Name', 'Default GET');
var response = restMessage.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if (httpStatus === 200) {
var jsonData = JSON.parse(responseBody);
return JSON.stringify(jsonData); // Return as a string for GlideAjax compatibility
} else {
return JSON.stringify({ error: 'Failed to fetch data', status: httpStatus });
}
} catch (e) {
return JSON.stringify({ error: e.message });
}
}
- Create one client script to call that script include. I am using onload client script to call it. You can call it from UI Action as well. Code would be same you just identify the place from where you wanna call.
function onLoad() {
// Call the Script Include via GlideAjax
var ga = new GlideAjax('FetchAPIData');
ga.addParam('sysparm_name', 'getAPIData'); // Method name in Script Include
ga.getXMLAnswer(function (response) {
if (response) {
try {
var data = JSON.parse(response);
if (data.error) {
console.error('Error fetching data:', data.error);
} else {
// Assuming the response contains a JSON object like { variable1: "value1", variable2: "value2" }
g_form.setValue('variable_name_1', data.variable1 || '');
g_form.setValue('variable_name_2', data.variable2 || '');
}
} catch (e) {
console.error('Error parsing response:', e);
}
}
});
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------