- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 04:32 AM - edited 04-09-2024 04:41 AM
Hi team,
I need help in below script:
var responseBody = [{"title":"Videos","sysid":"2eiej589eady9e6aesblo52"},{"title":"Sales","sysid":"25ic5ej589eady9e6aesblo87oed3"},{"title":"Enablement","sysid":"d9e3seady9e6aesblo525eplse36"}];
I want last 'sysid' of responseBody
this is only example i have 500 sysids in responseBody
Thanks
anil
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 05:29 AM
var responseBody = [{"title":"Videos","sysid":"2eiej589eady9e6aesblo52"},{"title":"Sales","sysid":"25ic5ej589eady9e6aesblo87oed3"},{"title":"Enablement","sysid":"d9e3seady9e6aesblo525eplse36"}];
var lastItem = responseBody[responseBody.length - 1];
var lastSysId = lastItem.sysid;
gs.info("Last 'sysid' of responseBody:" +lastSysId);
Please mark my answer helpful and correct.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 11:22 AM
Hi @Amit
The script is working fine in background script but script include returns undefined value
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 10:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 05:58 AM
You can try below
var responseBody = [
{"title":"Videos","sysid":"2eiej589eady9e6aesblo52"},
{"title":"Sales","sysid":"25ic5ej589eady9e6aesblo87oed3"},
{"title":"Enablement","sysid":"d9e3seady9e6aesblo525eplse36"}
];
// Get the last element of the responseBody array
var lastItem = responseBody[responseBody.length - 1];
// Retrieve the 'sysid' property of the last item
var lastSysId = lastItem.sysid;
// Output the last sysid
gs.info("Last sysid:", lastSysId);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks