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 01:50 AM
Hi @Prathamesh Chav ,
You have to parse the response body to be able to access the data as key value pairs
try {
var r = new sn_ws.RESTMessageV2('CLM Integration', 'Default GET');
r.setStringParameterNoEscape('Apttus__FF_Agreement_Number__c', crn_number);
// r.setStringParameterNoEscape('Apttus__FF_Agreement_Number__c', '00054549.0');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
if (httpStatus == 200) {
responseBody = JSON.parse(responseBody)
var compSys = new GlideRecord("core_company");
compSys.addEncodedQuery("nameSTARTSWITH" + responseBody.records[0].Account_Name__c);
compSys.query();
if (compSys.next()) {
var sys_Comp = compSys.sys_id;
}
//adding new line
responseBody.records[0].sys_idd = sys_Comp;
return JSON.stringify(responseBody);
}
you can try this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 02:14 AM
your code to query company should be within try block
were you able to parse and get the company name using this -> responseBody.records[0].Account_Name__c
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 03:03 AM - edited 02-20-2025 03:06 AM
Hi @Ankur Bawiskar ,
Still giving the same error after adding my code in try block
client side
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 03:13 AM
please share your complete script include, client script and sample response you are getting
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader