
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2021 07:05 AM
**** Edited as the screenshots contained sensitive work info***
Hi Guys
So I wrote a code to go to sys_groupmember table and get back the groups a user is a member of as an array, to then do an itteration to get the groups and check if the user is a member of a particular group by matching their sys_ids.
I get an issue where If I do method 1 (below):
1. Create object then bring back array of objects
then client side get that array and use evalJason to get the object and iterate through to separate the values that I can use:
This method works in Application for the Cat Item but in Portal causes an 'Unhandled exception in GlideAjax' error.
Reading around the community, I tried Option 2:
2. Turn Object into string and then doing iteration:
Server Side: using stringify to convert array to string
Client Side: parse the array itterate and use the resulting Object:
This version of the code gets me the Object and doesn't cause any JavaScript errors, but the resulting value comes back as 'undefined'
Although in the Alerts, I always get back values using either method before my iteration:
For me method 1 at least brings me back the value, but to work on Portal I need to use stringy.
So in Summary what I need to know is after I stringify the array in the Server script include, I pass it to the Client script, how do I get the singular value from the iteration that doesn't just return 'undefined'.
Kind Regards
Markell
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2021 07:17 AM
Hi,
for the 2nd approach
1) you can just return the stringified version of string
just use this
return JSON.stringify(array);
Also you require to push the groups then you should be using this
obj.sys_id = groupGr.getValue('group');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2021 07:17 AM
Hi,
for the 2nd approach
1) you can just return the stringified version of string
just use this
return JSON.stringify(array);
Also you require to push the groups then you should be using this
obj.sys_id = groupGr.getValue('group');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2021 07:32 AM
Both peices of advice guided me to what I needed. You are a saint and a scholar good sir.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2021 09:31 PM
Glad to help.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 07:45 AM
Were you able to find the solution? I am facing the similar issue but following your script(s) are not returning the same results for me. I am trying to go a step further and below is what I am trying to do:
- User Selects Reassign UI Action on workspace
- I am using g_modal and to show reference field to sys_user in the g_modal
- User then selects a user from the list
- My GlideAjax/Script Include gets called and should return the results based on the selected user
- then another g_modal should pop-up
- I am trying to either populate this g_modal with choices of groups retrieved from the script include or only display reference to group for the selected user
I am getting as far retrieving object and my alert show [object object] on the client side. I feel like I am so close to getting everything I need but just cannot figure out the last few steps.
Any help is much appreciated. Thanks!