In this article
we are able to see how to hide controls based on permissions, we placed a
button in display form and we want to show that button only for couple of
users, for this we created a SharePoint group added users in that group.
Add the below
code in notepad save it and place it in Site Assets.
Enter your GroupName as per your requirement.
Add the content
editor in the display form, Edit it and refer the file in this editor.
Now we can able
to see the button based on the permissions.
<html>
<head>
<script>
_spBodyOnLoadFunctionNames.push("CurrentUserInGroup");
function
CurrentUserInGroup()
{
$('#btnhidebutton').hide();
$.ajax({
url:
_spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('Your
SP GroupName')/Users?$filter=Id eq " + _spPageContextInfo.userId,
method: "GET",
headers: { "Accept":
"application/json; odata=verbose" },
success: function(data){
if(data.d.results[0] != undefined){
console.log(data.d.results[0]);
$('#btnhidebutton').show();
}
}
});
}
</script>
</head>
<input
type="button" id="btnhidebutton" value="Add
Button"/>
</html>