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 09:52 PM
at which line it's giving error?
Did you try to give hard-coded API response and see if it works?
what debugging have you done so far?
The script I shared should work fine, you should enhance it by adding some logs for debugging
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 09:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 10:14 PM
you didn't use the same script which I shared
try this
var clmCrmIntegration = Class.create();
clmCrmIntegration.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCrnNum: function() {
var crn_number = this.getParameter('clmcrn');
var obj = {};
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();
var httpStatus = response.getStatusCode();
if (httpStatus == 200) {
var jsonResponse = JSON.parse(responseBody); // Convert string to JSON
var startDate = jsonResponse.records[0].Apttus__Contract_Start_Date__c;
var endDate = jsonResponse.records[0].Apttus__Contract_End_Date__c;
obj['start'] = startDate.toString();
obj['end'] = endDate.toString();
var accountName = jsonResponse.records[0].Account_Name__c;
var gr = new GlideRecord('core_company');
gr.addEncodedQuery('nameSTARTSWITH' + accountName);
gr.setLimit(1);
gr.query()
if (gr.next()) {
obj['company'] = gr.getValue("sys_id");
}
return JSON.stringify(obj);
}
return '';
} catch (ex) {
var message = ex.message;
gs.error("Error in getCrnNum: " + message);
}
},
type: 'clmCrmIntegration'
});
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 11:26 PM - edited 02-20-2025 11:29 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 11:31 PM
did you debug script include and see what came in log?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader