0

I want to get Current User's SharePoint groups by programmatically.How can i get this information?

1

you can use below ajax call for getting groups of current user.

function getAllGroups(){
return jQuery.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/currentuser/?$expand=groups&$select=groups/Title",
    method: "GET",
    async: false,
    headers: { "Accept": "application/json; odata=verbose" }
});
}

getAllGroups().then(
    function(data){
    var groupArray = new Array();
    jQuery.each(data.d.Groups.results, function (i, result) {
    alert(result.Title);
        groupArray.push(result.Title);
    });
  },function(data){
    alert('fail');
 });
1

You can also do the same with popular PnPjs library:

import { sp } from "@pnp/sp";

sp.web.currentUser.select('groups/Title').expand('groups').get()
.then(data => {
    console.log(data.Groups);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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