Fetch the sys_id from json object

Chandu Telu
Tera Guru
Tera Guru

HI Team,

Please help me to fetch the sys_id value from json object

{

    "result":{

        "parent":"",

        "made_sla":"true",

        "caused_by":"",

        "watch_list":"",

        "upon_reject":"cancel",

        "sys_updated_on":"2017-05-26 03:35:02",


        "sys_id":"33acf340db4b320050315ec0cf96193f",

        "contact_type":"",

        "correlation_id":"",

        "location":"",

        "category":"inquiry"

    }

}

Thanks

Chandu Telu

1 ACCEPTED SOLUTION

Jeet
Tera Expert

Hi,



Use below code to parse JSON data



var data = '{ "result":{ "parent":"", "sys_id":"33acf340db4b320050315ec0cf96193f", "contact_type":"",}}';       // Demo json Data



var jsData= JSON.parse(data);   // convert json object into javascript object



var sysID = jsData["result"].sys_id ;




Thanks,


Jeet


View solution in original post

5 REPLIES 5

joebusuttil
ServiceNow Employee
ServiceNow Employee

Hi Chandu, I may just be getting confused by the output, but the fact that you have two pairs of curly braces (i.e. { } ) makes it seem like result is possibly contained within another object. If result.sys_id or result['sys_id'] both do not work then I would be looking for a way to get the name of the object which contains result. If this isn't helpful, please provide some context on what you have done to get the above output and how you are trying to consume it.


Karthik Reddy T
Kilo Sage

Hello Chandu,



Refer the below threads may helpful to you.



How to get the Change Request's sys_id inside a Business Rule's Script?




How to check nested json object value in sysparm_query?


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

Ahmed Hmeid1
Kilo Guru

Assuming you're storing the json object somewhere so i'm going to call it obj in this example:



var obj = {


    "result":{


        "parent":"",


        "made_sla":"true",


        "caused_by":"",


        "watch_list":"",


        "upon_reject":"cancel",


        "sys_updated_on":"2017-05-26 03:35:02",




        "sys_id":"33acf340db4b320050315ec0cf96193f",


        "contact_type":"",


        "correlation_id":"",


        "location":"",


        "category":"inquiry"


    }


};



var sysID = obj.result.sys_id;


shloke04
Kilo Patron

Hi,



You can do this by storing the Response in Object and then Dot walkin as mentioned below:



var object = {


    "result":{


        "parent":"",


        "made_sla":"true",


        "caused_by":"",


        "watch_list":"",


        "upon_reject":"cancel",


        "sys_updated_on":"2017-05-26 03:35:02",



        "sys_id":"33acf340db4b320050315ec0cf96193f",


        "contact_type":"",


        "correlation_id":"",


        "location":"",


        "category":"inquiry"


    }


};




To get Sys Id use the Below syntax:



var id = object.sys_id;



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke