How to populate selected fields on a case form load using REST API call in CSM servicenow ??
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2023 02:16 PM
I have a requirement to fetch values in fields , after receiving response for respective fields using REST API messages.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2023 01:58 AM
Hi @kumarprasanjeet ,
To fetch values for specific fields from the response received through the REST API message, you can modify your script as per your requirment
var r = new sn_ws.RESTMessageV2('JiraIntegrationEndpoint', 'Get Issue Details');
r.setEndpoint("https://.atlassian.net/rest/api/3/project");
var response = r.execute();
var responseBody = JSON.parse(response.getBody());
var httpStatus = response.getStatusCode();
if (httpStatus === 200) {
var ot = JSON.parse(responseBody);
for (var i = 0; i < ot.length; i++) {
var name = ot[i].name;
var id = ot[i].id;
var key = ot[i].key;
// Here, you can extract values for specific fields from the response and use them as needed.
var field1Value = ot[i].field1; // Replace 'field1' with the actual field name.
var field2Value = ot[i].field2; // Replace 'field2' with the actual field name.
// Insert the data into the desired table, e.g., 'u_jira_projects'.
var gr = new GlideRecord("u_jira_projects");
gr.initialize();
gr.u_name = name;
gr.u_id = id;
gr.u_key = key;
gr.u_field1 = field1Value; // Set the appropriate field name.
gr.u_field2 = field2Value; // Set the appropriate field name.
gr.insert();
}
}
Please mark it as solution proposed and helpful if its serves your purpose.
Thanks,
Anand