Question

I tried this:

_api/web/lists/getByTitle('listname')/items?$select=Editor/group,Editor/EMail&$expand=Editor/group,Editor/EMail

But this does not seem to work.

How to get the SharePoint groups of the user who has modified a list item?

Was it helpful?

Solution

You cannot get the SharePoint groups of user directly by expanding user field (in single call) using REST APIs.

First, you need to get the user Id of the user who modified the list items using:

<Site URL>/_api/web/lists/getByTitle('listname')/items?$select=Editor/Id&$expand=Editor

Then in success function of above call you can use below code to get the SharePoint groups of user:

function getCurrentUserGroupColl(UserID) {
    $.ajax ({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + UserID + ")/Groups",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            /* get all group’s title of current user. */
            var results = data.d.results;

            for (var i = 0; i < results.length; i++) {
                console.log(results[i].Title);
            }
        }
    });
}

Here UserID is the ID you got from above REST call.

Reference: SharePoint 2013: Get current user group collection through Rest api

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top