How to get first array element
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 12:52 PM
I have the below code and i am unable to get the first array element
var idset = workflow.scratchpad.idvalue;
var idset2 = workflow.scratchpad.idvalue2;
var idset3 = workflow.scratchpad.idvalue3;
var idset4 = workflow.scratchpad.idvalue4;
var idset5 = workflow.scratchpad.idvalue5;
var arr = [];
arr.push(idset, idset2, idset3, idset4, idset5);
for (var i in arr) {
var myObj = arr[i];
var r = new sn_ws.RESTMessageV2('Cisco ISE', 'Get voucher details');
r.setStringParameterNoEscape('id', myObj);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var jsonObj = JSON.parse(responseBody);
var UN = jsonObj.GuestUser.guestInfo.userName;
var unarr = [];
unarr.push(UN);
gs.log(unarr+"unarr");
var x = unarr[0].toString();
gs.log(x+"unarrx");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 12:59 PM
Hello,
can you try putting log for
var UN = jsonObj.GuestUser.guestInfo.userName;
gs.info('My JSON'+UN);
first check this value is coming from the response or not and let me know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 09:37 PM
I am getting myobj but not getting the response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 09:44 PM
Can you share how your response body looks like?
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 09:49 PM
Below is the response body, But my script is not givinf response with the code i wrote. But it is working in background script
{
"GuestUser" : {
"id" : "245b3a95-d0fb-11ec-b93e-328fa1c8a142",
"name" : "2a5m2f",
"guestType" : "BI-MyShop",
"status" : "AWAITING_INITIAL_LOGIN",
"sponsorUserName" : "myshop",
"sponsorUserId" : "c15f0072-f535-11e7-be5b-6cb2ae981a48",
"guestInfo" : {
"userName" : "2a5m2f",
"password" : "9047AK",
"creationTime" : "05/11/2022 09:22",
"enabled" : false,
"notificationLanguage" : "English"
},
"guestAccessInfo" : {
"validDays" : 5,
"location" : "In"
},
"customFields" : { },
"link" : {
"rel" : "self",
"href" : "https://iseapi/ers/config/guestuser/245b3a95-d0fb-11ec-b93e-328fa1c8a142",
"type" : "application/json"
}
}
}