
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 09:26 PM
Hi All,
I have the below JSON object:
json69 is:{"last_updated":"2019-11-16 04:28:46","catalog_item":{"display_value":"","value":null},"hr_criteria":{"display_value":"US All Employees",
"value":"31df2c2adb61a7003acf30cf9d9619ca"},"icon":"success-icon-wand.png","active":"1","hover_icon":"success-icon-hover-wand.png",
"userFav":[{"sys_id":"e83663c3db814410fd0a38ff9d96199e","url_target":"_blank","icon":"success-icon-wand.png","typeString":"Link","item_sys_id":"7b2f4535db936b80fd0a38ff9d9619c1",
"hover_icon":"success-icon-hover-wand.png","href":"https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844","title":"Wand","table":null,"order":"0"}],
"title":"Wand","url":{"display":"https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844",
"value":"https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844"},"sys_id":"7b2f4535db936b80fd0a38ff9d9619c1","url_target":"_blank",
"typeString":"Link","checked":true}
I want to access the item_sys_id from the above JSON object. However when I am trying to retrieve it , it is giving me undefined.
Help is appreciated.
Regards,
Dheeraaj
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 11:32 PM
Hi
I used exactly same JSON object which you had. Copy paste the below in background script and hit "Run Script"
Refer the gs.print, that is what you are looking for.
Thanks,
Vivek Anand
Please Note: If my response helps you to fix this issue, please mark it as correct!
var json69 =
{
"last_updated": "2019-11-16 04:28:46",
"catalog_item": {
"display_value": "",
"value": null
},
"hr_criteria": {
"display_value": "US All Employees",
"value": "31df2c2adb61a7003acf30cf9d9619ca"
},
"icon": "success-icon-wand.png",
"active": "1",
"hover_icon": "success-icon-hover-wand.png",
"userFav": [
{
"sys_id": "e83663c3db814410fd0a38ff9d96199e",
"url_target": "_blank",
"icon": "success-icon-wand.png",
"typeString": "Link",
"item_sys_id": "7b2f4535db936b80fd0a38ff9d9619c1",
"hover_icon": "success-icon-hover-wand.png",
"href": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844",
"title": "Wand",
"table": null,
"order": "0"
}
],
"title": "Wand",
"url": {
"display": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844",
"value": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844"
},
"sys_id": "7b2f4535db936b80fd0a38ff9d9619c1",
"url_target": "_blank",
"typeString": "Link",
"checked": true
};
gs.print(json69.userFav[0].item_sys_id);
/****OUTPUT****
7b2f4535db936b80fd0a38ff9d9619c1
****OUTPUT****/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 09:42 PM
var data = {your JSON};
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 11:57 PM
Hi,
I have tried the above script but got the below error :
org.mozilla.javascript.EcmaError: Cannot read property "0" from undefined
Regards,
Dheeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 09:45 PM
var myObj, x;
myObj = {
"last_updated": "2019-11-16 04:28:46",
"catalog_item": {
"display_value": "",
"value": null
},
"hr_criteria": {
"display_value": "US All Employees",
"value": "31df2c2adb61a7003acf30cf9d9619ca"
},
"icon": "success-icon-wand.png",
"active": "1",
"hover_icon": "success-icon-hover-wand.png",
"userFav": [
{
"sys_id": "e83663c3db814410fd0a38ff9d96199e",
"url_target": "_blank",
"icon": "success-icon-wand.png",
"typeString": "Link",
"item_sys_id": "7b2f4535db936b80fd0a38ff9d9619c1",
"hover_icon": "success-icon-hover-wand.png",
"href": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844",
"title": "Wand",
"table": null,
"order": "0"
}
],
"title": "Wand",
"url": {
"display": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844",
"value": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844"
},
"sys_id": "7b2f4535db936b80fd0a38ff9d9619c1",
"url_target": "_blank",
"typeString": "Link",
"checked": true
}
x = myObj["userFav"][0].item_sys_id;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 11:17 PM
Try below:
var payload =
{
"userFav": [
{
"sys_id": "e83663c3db814410fd0a38ff9d96199e",
"url_target": "_blank",
"icon": "success-icon-wand.png",
"typeString": "Link",
"item_sys_id": "7b2f4535db936b80fd0a38ff9d9619c1",
"hover_icon": "success-icon-hover-wand.png",
"href": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844",
"title": "Wand",
"table": null,
"order": "0"
}
],
"title": "Wand",
"url": {
"display": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844",
"value": "https://myapps.microsoft.com/success.com/signin/WAND/70621e21-d8e5-47d0-ba36-3e9eb4660844"
},
"sys_id": "7b2f4535db936b80fd0a38ff9d9619c1",
"url_target": "_blank",
"typeString": "Link",
"checked": true
};
var x= payload.userFav;
var myJSON = JSON.stringify(x);
gs.print(myJSON);
var y='';
for(i in payload.userFav){
y+=payload.userFav[i].item_sys_id;
}
gs.print(y);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks