- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 02:36 PM
Hi,
When using the Microsoft AD Spoke, Lookup User action in Flow Designer, I set the property list to return the user's groups from AD. The attribute in AD is MemberOf.
The lookup is working and I retrieve the user's memberof groups in a JSON String. This string can't be used in a for each loop, so I created a custom action to parse the JSON string. However, I am having a hard time.
Some users are only in 1 group, so the JSON looks like this.
{
"MemberOf":"CN=Bright Executives,OU=SNOW,OU=Groups,OU=Connected,DC=Dev,DC=Green,DC=com"
}
Then there are some that have multiple groups and this is how the return looks.
{
"MemberOf":
[
"CN=Group_22c6,OU=MGroups,OU=Groups,OU=Resources,OU=Context,DC=Green,DC=com",
"CN=Bright Executives,OU=SNOW,OU=Groups,OU=Connected,DC=Dev,DC=Green,DC=com"
]
}
I tried to use the Parser step action in flow, but it is based on a structure and either option doesn't fit the other. I even tried just coding it directly in a script but my return looks like this.
CN=Group_22c6,OU=MGroups,OU=Groups,OU=Resources,OU=Context,DC=Green,DC=com,CN=Bright Executives,OU=SNOW,OU=Groups,OU=Connected,DC=Dev,DC=Green,DC=com
If I tried to turn this into an array, it would loop through all the items, separated by comma. That could get long especially if they have more than 10 groups.
Because when you return groups from Active Directory, it returns as the distinguishedname and not just the display name. The real information that I need from these are the CN= text.
I need to be able to push the items into an array, no matter if it is just 1 group or multiple so that I can use the foreach loop.
Does anyone have any ideas, how I can go about this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2022 12:47 AM
@Dazler Tried and tested solution. Parse it using the code
Result 2 (when user is part of multiple group):
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 11:29 PM
Are you able to push to an array by calling from the JSON returned? I tested one of your JSON outputs to see if this would work and it did in a background script. Just need to make sure the format stays this way otherwise you would need to adjust the substring by determining the index of the starting and ending points of the strings in the array.
var obj = {"MemberOf":["CN=Group_22c6,OU=MGroups,OU=Groups,OU=Resources,OU=Context,DC=Green,DC=com","CN=Bright Executives,OU=SNOW,OU=Groups,OU=Connected,DC=Dev,DC=Green,DC=com"],"test":"test"};
var array = [];
for(var i = 0; i < obj.MemberOf.length; i++){
array.push(obj.MemberOf[i].substring(3,obj.MemberOf[i].indexOf(",")));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2022 05:57 AM
When my output is multiple groups returned, then yes the format pretty much stays the same. I tested your code in background script and it worked. However, I still have to solve for if a single group is returned. That format is different.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2022 12:47 AM
@Dazler Tried and tested solution. Parse it using the code
Result 2 (when user is part of multiple group):
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2022 06:53 AM