How to add key and value in the response we got from rest message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 01:41 AM - edited 02-20-2025 01:47 AM
Hi Team,
I am fetching response from restmessage but from there I am getting company name, start date and end date,
start date and end date I am able to populate on change form, but for company name which is reference field I am trying to fetch sys_id from the same script include which is I am using to call rest message and fetch the responseBody and I am passing that responseBody to the client side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 05:05 AM
Your script is modifying responseBody.records[0] directly, but responseBody is a string, not a JSON object. You need to parse it first before modifying it.
try {
var r = new sn_ws.RESTMessageV2('CLM Integration', 'Default GET');
r.setStringParameterNoEscape('Apttus__FF_Agreement_Number__c', crn_number);
var response = r.execute();
var responseBody = response.getBody(); // Response is a string
var httpStatus = response.getStatusCode();
}
catch (ex) {
var message = ex.message;
}
if (httpStatus == 200) {
var jsonResponse = JSON.parse(responseBody); // Convert string to JSON
var compSys = new GlideRecord("core_company");
compSys.addEncodedQuery("nameSTARTSWITH" + jsonResponse.records[0].Account_Name__c);
compSys.query();
var sys_Comp = "";
if (compSys.next()) {
sys_Comp = compSys.getValue("sys_id"); // Fetch sys_id correctly
}
jsonResponse.records[0].sys_idd = sys_Comp; // Modify JSON object
return JSON.stringify(jsonResponse); // Convert JSON back to string
}
Please mark correct/helpful if this help you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 09:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 09:52 PM
What issue/error are you getting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 11:27 PM