Column formatting / Show or hide columns based on user permission

Copper Contributor

Hi guys,

 

I just wanted to let you know that by pure chance :) I managed to show/hide list columns based on the permission of the current user. For this, I use the PermMask attribute.

In this example, I only show the column value, if the user permission is higher than 'read' permission:

 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "visibility": "=if([$PermMask]>='0xb00','hidden','visible')"
  },
  "txtContent": "=if([$PermMask]>='0xb00','read-only','more than read')"
}

 

 

In a real life use case, I use this to show a "Run flow" button to only those users, who have at least an edit permission for the specific list item.

I hope this helps somebody :)

8 Replies
An elegant solution.
Unfortunately, it does not work in sharepoint 2019.
Is it possible to modify it for sharepoint 2019?

@Ivan_Volkov For SharePoint 2019, you have to use the Abstract Syntax Tree (AST) expressions using operator and operands. Try this

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v1/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "visibility": {
      "operator": "?",
      "operands": [
        {
          "operator": ">=",
          "operands": [
            "[$PermMask]",
            "0xb00"
          ]
        },
        "hidden",
        "visible"
      ]
    }
  },
  "txtContent": {
    "operator": "?",
    "operands": [
      {
        "operator": ">=",
        "operands": [
          "[$PermMask]",
          "0xb00"
        ]
      },
      "read-only",
      "more than read"
    ]
  }
}

 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@ganeshsanap 

Thank you! Unfortunately, it didn't help.

I assumed that the problem is in the json-schemas/sp/v2 it should be json-schemas/sp/v1

(To format columns on SharePoint 2019, please use https://developer.microsoft.com/json-schemas/sp/v1...

It didn't help.

Either I format the column incorrectly, or, maybe, the problem is in "[$PermMask]",
"0xb00" - it differs from Sharepoint Online.

edit column.jpg

@Ivan_Volkov did you figure out a way around this? I'm trying to accomplish the same thing.

Another option is to create separate views, just show/hide the views for specific users.
How can you make views for specific users?

@Oyelg Unfortunately, there is no way to create view for specific users (view audience targeting) in SharePoint modern experience.

 

However, you can do it using SharePoint classic experience. Check my answers on below links for more information: 

  1. Set Target Audience by specific view in SharePoint List using Modern Experience 
  2. View for individual user groups 

Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.