문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top