0

In javascript, I'm trying to get a list of all the groups to which a user belongs.

For the current user I can use SPServices + GetGroupCollectionFromUser. But for other users I would need the login name, which I don't have. I need to query by user name.

Is there an alternative to GetGroupCollectionFromUser that takes a user name? Or some other way to do this?

It doesn't have to be through SPServices, using the REST API is also fine.

Thanks!

1 Answer 1

1

If the REST API is acceptable, you can get the groups for a user by using their user name using the following query:

https://server/sites/site/_api/web/siteusers?$filter=Title eq 'The User Name'&$select=Title,Id,Groups/Title,Groups/Id&$expand=Groups

Obviously you can choose to return more information about the user or the groups by including more fields in the $select.

1
  • Great. I made it work by querying first the user login (with REST) and then using GetGroupCollectionFromUser but your approach is much simpler and with just one request. Thanks!
    – Gelu
    May 19, 2020 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.