Rest API to check User is available in SharePoint Group or not

Checking the the User is available in Specified Group //To check whether user is present in current group or not var isUserInGroup = isMemberofGroup("GroupName", currentLoginUser);
isUserInGroup.done(function (results) { if (results[0] != undefined) { console.log('User is Present in current AssignedTo Group'); userPresentInGroup = true; //Check whether current item Activity Status as Active then show forms otherwise don't display form } else { console.log('User is Not present in current AssignedTo Group'); } });



//Find user is member within group function isMemberofGroup(groupName, userId) { var deferred = new jQuery.Deferred(); var endpointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('" + groupName + "')/Users?$filter=Id eq " + userId; jQuery.ajax({ url: endpointUrl, type: "GET", headers: { "accept": "application/json;odata=verbose" }, success: function (data) { deferred.resolve(data.d.results); }, error: function (data) { alert(JSON.stringify(error)) deferred.reject(error); } }); 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

SharePoint SPFx Intro & Configuration to Create New SPFx Solution

Filtering the Sharepoint List Taxonomy Column using Rest API