GetGroupCollectionFromUser

Apr 22, 2013 at 3:45 AM
Hi Marc,
I'm working with GetGroupCollectionFromUser to try and filter a dropdown list based on the group a user is a member of. From what I can see when I use if($(xData.responseXML).find("Group[Name='GroupName']").length == 1){..} the value returned is the name of the last group returned in the collection. Is this correct? The behaviour I'm really looking for is to test whether 'GroupName' is ONE OF the groups returned. Can you suggest how I achieve this?

eg. The method may return <group Name='Group01'/><group Name='Group2'/> for user A.
I want to know if User A is a member of Group01 and set a variable accordingly. I don't care if they're a member of Group02 or not.
Coordinator
Apr 22, 2013 at 11:34 AM
MartyNZ:

The snippet you show will look for an element with the Name='GroupName' and then test to see if that value exists. I think you'll need to debug to see if it's doing exactly what you expect and also to see if the group name is in fact in the returned data.

M.
Apr 22, 2013 at 12:02 PM
The 'if' function isn't returning a value from your XML. It's only going to evaluate the condition you specify. I use that same condition throughout my code and it works consistently. For example...
var booAdminUser;
if($(xData.responseXML).find("Group[Name='access_AppAdmins']").length == 1) {
    booAdminUser = true;
}
It's as simple as that. If the user is a member of 'access_AppAdmins', then the variable 'booAdminUser' gets set to 'true', otherwise, that line gets skipped.

Geoff