I am working on SharePoint 2016 on-premises environment. I need to implement the some functionality based on the result whether the currently logged-in user is a part of a security group or not using javascript/jquery. Can someone advise on how I can check the user membership in a security group?
1 Answer
You can use SPServices to check the Current User. Here is an example
var userInGroup=false;
var site = "/sites/Sitename";
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser({
webURL: site
}),
webURL: site,
async: false,
completefunc: function (xData, Status){
if ($(xData.responseXML).find("Group[Name='Security Group name']").length == 1){
userInGroup=true;
}
}
});
if(userInGroup)
{
$("input[title='Priority Confirmed']").closest("tr").show();
}
else
{
$("input[title='Priority Confirmed']").closest("tr").hide();
}
});
Here is an article for reference SPServices
-
Hello @rrr : thanks for your response. Well, I tried to implement the solution provided by you, but it does not work for me. To be on the same page, I want to clarify that here by security group I am referring to the distribution list that has been converted to security group to make it detectable in SharePoint environment. Any other suggestions?– Tarun KNov 24, 2017 at 12:24