In this article, you will see how to check logged in user is part of a given SharePoint Group. This is for SharePoint online environment and by using javascript.
you can put this code in content editor webpart to test.
Before using this script, make sure you have the file "jquery.SPServices-0.7.1a.min.js" in any library that you can refer in below code. In below example, i used the file under "SiteAssets\"
Also please make sure Jquery.js file is referred in your page already.
you can put this code in content editor webpart to test.
Before using this script, make sure you have the file "jquery.SPServices-0.7.1a.min.js" in any library that you can refer in below code. In below example, i used the file under "SiteAssets\"
Also please make sure Jquery.js file is referred in your page already.
<script type="text/javascript" src="https://sharepointsitecollection/site1/SiteAssets/jquery.SPServices-0.7.1a.min.js"></script>
<script type="text/javascript">
var isValidatUser=false;
$(document).ready(function() {
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function(xData, Status) {
if ($(xData.responseXML).find("Group[Name='SP Group Name']").length == 1)
{
//user in group
}
else {
// user not part of group
}
}
});
});
</script>
<script type="text/javascript">
var isValidatUser=false;
$(document).ready(function() {
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function(xData, Status) {
if ($(xData.responseXML).find("Group[Name='SP Group Name']").length == 1)
{
//user in group
}
else {
// user not part of group
}
}
});
});
</script>
No comments:
Post a Comment