Checking the User Groups in SharePoint using REST API.

Getting the Login Users Groups from SharePoint Site

//The below line will used to get the user groups from the getUserPermissions Method

var permissionResults = getUserPermissions(_spPageContextInfo.webAbsoluteUrl, _spPageContextInfo.userId);

permissionResults.done(function (groups) { $(".menu-item-text:contains('Admin')").parent().parent().parent().hide(); var groupInfo = jQuery.grep(groups, function (group, index) { //return (group.Title == "GlobalScore Admins"); if (group.Title == "Site Full Control Admins" || group.Title == "Site Contribute Admins") { alert("User is available in Admin Groups"); } else alert("User is not Admin..."); }); });


//Getting the Login User SharePoint Group Details
function getUserPermissions(webUrl, userId) { var deferred = new jQuery.Deferred(); jQuery.ajax({ url: webUrl + "/_api/web/GetUserById(" + userId + ")/Groups", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function (data) { var results = data.d.results; deferred.resolve(results); } }); return deferred.promise(); }





Happy Coding....Sharing is caring .... Keep Smiling...

Comments

Popular posts from this blog

SharePoint 2013 Keyword Query (KQL) Content Class Property Restrictions

Filtering the Sharepoint List Taxonomy Column using Rest API

SharePoint CSOM to Create Folders and Sub Folders based on Excel Data