How to add key and value in the response we got from rest message?

Prathamesh Chav
Tera Contributor

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.

 

PrathameshChav_0-1740044470079.png

 

 


 
Updating Media

 

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){

             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);
        }
       

    },
 
getting this error message
PrathameshChav_1-1740044827032.png

 


 

 

23 REPLIES 23

Hi @Ankur Bawiskar ,

currently a response I am getting error message

@Prathamesh Chav 

you can't test unless you get an API response

try to hard-code the API response and see if it works, if yes then it will work when you get actual API response as well

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Can't I add sys_id in response Body and make one single object, because in future I  may need few may parameters from response body and for me its easy when its I am fetching response body into client side

@Prathamesh Chav 

that's what I am doing. forming single json object in script include and returning complete json

then in client side parsing it

In future you can update code in script include and also in client side

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Tried this sccript still giving the same error message