Check Whether user belongs to SharePoint Group using REST api
How to Check Whether user belongs to SharePoint Group using REST api
Code -
$(document).ready(function(){
isOwnerGroupMember();
});
function isOwnerGroupMember() {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('Test Owners')/Users?$filter=Id eq " + _spPageContextInfo.userId,
method: "GET",
async: false,
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data) {
if (data.d.results.length == 0) {
console.log("User not in group : Test Owners");
}
else {
console.log("User in group : Test Owners");
}
},
error: function(err) {
console.log("Error while checking user in Owner's group");
}
});
}
Comments
Post a Comment