how to fetch object/Json ?

Prathamesh Chav
Tera Contributor

Hi Team,

 

I am fetching one record in rest message and I want only particular field.

PrathameshChav_0-1739442775387.png

 

Here I want to fetch "Apttus__FF_Agreement_Number__c"?

can anyone help me in this?

PrathameshChav_1-1739442823954.png

 if(g_form.getValue("crn") != ""){

        var gr = new GlideAjax("global.clmCrmIntegration");
            gr.addParam('sysparm_name', "getCrnNum"); //Method
            //gr.addParam('sysparm_crn',crn); //Parameters
            gr.getXMLAnswer(getResponse);

                function getResponse(response){
        var res = JSON.parse(response);
         g_form.addInfoMessage(res);
   
}
 
Thanks
1 ACCEPTED SOLUTION

@Prathamesh Chav 

this should work

var jsonString = '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Apttus__APTS_Agreement__c","url":"/services/data/v58.0/sobjects/Apttus__APTS_Agreement__c/a086t000001eHdqAAE"},"Apttus__FF_Agreement_Number__c":"00054549.0","Apttus__Contract_Start_Date__c":"2023-04-19","Apttus__Contract_End_Date__c":"2023-04-26","Account_Name__c":"ABC Account","Apttus__Status__c":"Activated"}]}';

// Parse the JSON string
var jsonObj = JSON.parse(jsonString);

// Retrieve the value for Apttus__FF_Agreement_Number__c
var agreementNumber = jsonObj.records[0].Apttus__FF_Agreement_Number__c;

alert('Apttus__FF_Agreement_Number__c: ' + agreementNumber);

Output: I tried in background script and it worked fine

 

AnkurBawiskar_0-1739448762408.png

 

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Prathamesh Chav 

share that json here.

you should easily parse it and get that value using this

Ensure you give the correct underscore etc

var val = res.records[0].attributes['Apttus__FF_Agreement_Number__c'];
alert(val);

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 ,

 

Sorry @Ankur Bawiskar ,its not working please check the JOSN I have shared

 

Info Message{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Apttus__APTS_Agreement__c","url":"/services/data/v58.0/sobjects/Apttus__APTS_Agreement__c/a086t000001eHdqAAE"},"Apttus__FF_Agreement_Number__c":"00054549.0","Apttus__Contract_Start_Date__c":"2023-04-19","Apttus__Contract_End_Date__c":"2023-04-26","Account_Name__c":"ABC Account","Apttus__Status__c":"Activated"}]}

@Prathamesh Chav 

this should work

var jsonString = '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Apttus__APTS_Agreement__c","url":"/services/data/v58.0/sobjects/Apttus__APTS_Agreement__c/a086t000001eHdqAAE"},"Apttus__FF_Agreement_Number__c":"00054549.0","Apttus__Contract_Start_Date__c":"2023-04-19","Apttus__Contract_End_Date__c":"2023-04-26","Account_Name__c":"ABC Account","Apttus__Status__c":"Activated"}]}';

// Parse the JSON string
var jsonObj = JSON.parse(jsonString);

// Retrieve the value for Apttus__FF_Agreement_Number__c
var agreementNumber = jsonObj.records[0].Apttus__FF_Agreement_Number__c;

alert('Apttus__FF_Agreement_Number__c: ' + agreementNumber);

Output: I tried in background script and it worked fine

 

AnkurBawiskar_0-1739448762408.png

 

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

Community Alums
Not applicable

Hi @Prathamesh Chav ,

 

You can refer to the below video to understand how can we pass data using GlideAjax. 

 

Although, if you want to pass only a single value, you can directly use the following script and use it directly in your client script (no need of JSON). Ensure varname is a string type of field

return varname;

 

Please mark this response as Correct Answer/ Helpful if it helped you.

 

 

Cheers,

Hardit Singh