Use XSLT to hide columns in SharePoint list forms

In this post i will explain how XSLT can be used to hide the list columns in forms for users with insufficient previleges.

After you open your site and the list in SharePoint designer, create custom forms for New, Edit and Display forms.

Open each of the forms and select the column which should be shown based on user permissions.


Expand the Conditional Formatting option on the ribbon and select Show Content.
In the next screen click on Advanced.
In the pop up that appears after that, search for the function called IfHasRights
This function will determine whether the current user has the rights specified and will do the formatting accordingly, based on the result.


The permission mask specified is determined as the sum of the permission masks for the permissions required. Below mentioned are the permission masks for the permissions.

ViewListItems - 1
AddListItems - 2
EditListItems - 4
DeleteListItems - 8
ApproveItems - 16
OpenItems - 32
ViewVersions - 64
DeleteVersions - 128
CancelCheckout - 256
PersonalViews - 512
ManageLists - 2048
ViewFormPages - 4096
Open - 65536
ViewPages - 131072
AddAndCustomizePages - 262144
ApplyThemeAndBorder - 524288
ApplyStyleSheets - 1048576
ViewUsageData - 2097152
CreateSSCSite - 4194314
ManageSubwebs - 8388608
CreateGroups - 16777216
ManagePermissions - 33554432
BrowseDirectories - 67108864
BrowseUserInfo - 134217728
AddDelPrivateWebParts - 268435456
UpdatePersonalWebParts - 536870912
ManageWeb - 1073741824
UseRemoteAPIs - 137438953472
ManageAlerts - 274877906944
CreateAlerts - 549755813888
EditMyUserInfo - 1099511627776
EnumeratePermissions - 4611686018427387904

Give appropriate mask as shown in the screenshot above and save the form.
The next time the users open the form, they will see the column only if they have enough permissions.
Ofcourse you have to do the same to the label(Deparment) beside the text box you selected previously


This is how the form will appear for users who do not have enough previleges.

Comments

  1. Hi Naveed,

    Your blog is like encyclopedia of SharePoint. Great piece of work.
    I have a doubt, users of what kind of permissions will not see the Department column ?

    Thanks,

    Avinah Reddy

    ReplyDelete
  2. Thanks for that comment :).
    In the example shown(screenshot) the permission mask used is 2048 which is for Manage Lists. So the users who have these permissions will be able to view it. It will be hidden for all the other users who do not have this permission.

    ReplyDelete
  3. You can use SPServices and jQuery to Hide SharePoint List Columns based on User Permissions:

    http://www.sharepointdiary.com/2013/07/hide-sharepoint-list-columns-based-on-user-permissions.html#ixzz2aB7h7a4o

    ReplyDelete

Post a Comment

Popular posts from this blog

Create a Custom Timer Job in SharePoint 2010

Create web part pages with custom layouts in SharePoint 2010

Config file for SharePoint custom timer jobs