Requirement: We've a "Requests" link in our Help Desk site. The "Status" field in help desk requests list should be hidden when users create new entry in the list. Same time, Status field must be visible to people in "Help desk operators" group.
So, the requirement is to hide SharePoint List Form field based on user permissions!
Solution: Use SPServices to check whether the current user is member of a particular group. If not, hide the field using jQuery (or you can make the field Read-only too: How to Make SharePoint List Column Read Only ). Here is the detailed steps:
Instead of content editor web part, You can also edit the NewForm.aspx or EditForm.aspx file and place the code under "PlaceHolderAdditionalPageHead" to hide fields in SharePoint list forms.
Here is the NewForm.aspx view for "Help Desk Operators" - Note that the "Status" field is visible.
and here is the view for end-users: SharePoint list columns hidden based user permissions.
So, the requirement is to hide SharePoint List Form field based on user permissions!
Solution: Use SPServices to check whether the current user is member of a particular group. If not, hide the field using jQuery (or you can make the field Read-only too: How to Make SharePoint List Column Read Only ). Here is the detailed steps:
- Place the below script in a text file, upload to any SharePoint library of the site.
- Edit the NewForm.aspx, Add a content editor web part just below form fields, point the script file in CEWP and make the content editor web part hidden.
<!-- jQuery Reference. You can refer it from Layouts Folder/Doc Library too, after uploading the script. --><script src="http://code.jquery.com/jquery-1.10.1.min.js"></script><!-- Download SPServices from: http://spservices.codeplex.com/ Or use this CDN --><script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script><script type="text/javascript"> $(document).ready(function() { $().SPServices({ operation: "GetGroupCollectionFromUser", userLoginName: $().SPServices.SPGetCurrentUser(), async: false, completefunc: function(xData, Status) { var xml = xData.responseXML.xml; //If the current User does belong to the group "Service desk Operators" if (xml.search('Service Desk Operators') == -1) { // alert("No, User Doesn't Exists!"); $("select[title=Status]").parent().parent().parent().hide(); //or use: $('td.ms-formlabel:contains("Status")').parent().hide(); //You can also use: $('nobr:contains("Status")').closest('tr').hide(); } } }); }); </script>
Instead of content editor web part, You can also edit the NewForm.aspx or EditForm.aspx file and place the code under "PlaceHolderAdditionalPageHead" to hide fields in SharePoint list forms.
Here is the NewForm.aspx view for "Help Desk Operators" - Note that the "Status" field is visible.
and here is the view for end-users: SharePoint list columns hidden based user permissions.