This SharePoint tutorial, we will discuss how to disable document edit properties based on user permissions in SharePoint document library using SPServices and sputility js. The code will work in SharePoint Online as well as SharePoint 2013/2016.
Here I have a SharePoint document library which has a metadata column as “Department” which is a choice column. Here my requirement is, whenever a user tries to change the Department, then it will check if the user belongs to “Finance Team Approvers” SharePoint group or not.
- How to give unique permission to a folder in SharePoint Online document library
- SharePoint Video Tutorials
- Free SharePoint Training for beginners
Disable document edit properties based on user permission in SharePoint document library
Here we will do this by using client-side code like SPServices and sputility.js.
Open the library edit form and add a script editor web part in the page.
Example:
https://onlysharepoint2013.sharepoint.com/sites/SharePointSky/TestDocumentLibrary/Forms/EditForm.aspx
Below is the full code which will trigger on dropdown selected change. And first we are keeping the old selected value and if the user does not belong to the SharePoint group, then we will set the old value in the dropdown.
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
<script src="https://onlysharepoint2013.sharepoint.com/sites/SharePointSky/SiteAssets/sputility.min.js"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("ourFunctionName");
function ourFunctionName()
{
var oldvalue=$("select[Title='Department']").val();
$("Select[Title='Department']").change(function () {
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function (xData, Status) {
var fta = "false";
if (($(xData.responseXML).find("Group[Name='Finance Team Approvers']").length > 0)) {
fta = "true";
}
var newValue=$("select[Title='Department']").val();
if (fta == "true") {
}
else {
alert("You are not authorized to change to the status");
$("select[Title='Department']").val(oldvalue);
}
}
});
});
}
</script>
Save the above code.
Now, I logged with a user who is not a part of the SharePoint group (Finance Team Approvers), when the user tries to change the department, it will show a message, you are not authorized to change the status. And also, the drop-down selected value will reset it to the previously selected value in the edit form.

Disable document edit properties based on user permission in SharePoint document library (Page load)
The above code will check in the dropdown selected changed event, but sometimes we need to check this in the page load itself.
So I have modified the code little bit so that it will check if the user belongs to the particular SharePoint group in the page load itself. And if the user does not belong to the SharePoint group then it will go back to the previous page.
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
<script src="https://onlysharepoint2013.sharepoint.com/sites/SharePointSky/SiteAssets/sputility.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(ourFunctionName, "sp.js");
});
function ourFunctionName()
{
var oldvalue=$("select[Title='Department']").val();
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function (xData, Status) {
var fta = "false";
if (($(xData.responseXML).find("Group[Name='Finance Team Approvers']").length > 0)) {
fta = "true";
}
var newValue=$("select[Title='Department']").val();
if (fta == "true") {
}
else {
alert("You are not authorized to change to the status");
$("select[Title='Department']").val(oldvalue);
window.history.back();
}
}
});
}
</script>
You may like following SharePoint tutorials:
- Autocomplete feature in SharePoint 2013 list column using SPServices in SharePoint 2013
- Export SharePoint list data to excel programmatically using JavaScript and SPServices
- Query User Profile Service for Multiple Users in SharePoint Using SPServices
- Show hide div based on user permission using SPServices in SharePoint 2013
- SharePoint 2013 Online Retrieve Current user details using SPServices
- Cascading dropdown in SharePoint 2013/2016/Online using jQuery
- Uncaught ReferenceError $ is not defined and Uncaught TypeError Cannot read property ‘SPGetCurrentUser’ of undefined
- Display SharePoint List items in HTML Table using JSOM in SharePoint Hosted App
- Bind SharePoint List items in dropdown list programmatically using CSOM
- Cascading Dropdown in SharePoint List using jQuery
Hope this SharePoint tutorial explains how to disable document edit properties based on user permission in SharePoint document library.
I am Bijay a Microsoft MVP (8 times – My MVP Profile) in SharePoint and have more than 15 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com
Great! What if you would like to gray out an input box, even before the user attempts to change the value?