Column formatting / Show or hide columns based on user permission

%3CLINGO-SUB%20id%3D%22lingo-sub-3017542%22%20slang%3D%22en-US%22%3EColumn%20formatting%20%2F%20Show%20or%20hide%20columns%20based%20on%20user%20permission%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3017542%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20guys%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20wanted%20to%20let%20you%20know%20that%20by%20pure%20chance%20%3A)%3C%2Fimg%3E%20I%20managed%20to%20show%2Fhide%20list%20columns%20based%20on%20the%20permission%20of%20the%20current%20user.%20For%20this%2C%20I%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fquestions%2F49129470%2Fconfusing-permmask-values-in-sharepoint-online%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EPermMask%20attribute.%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EIn%20this%20example%2C%20I%20only%20show%20the%20column%20value%2C%20if%20the%20user%20permission%20is%20higher%20than%20'read'%20permission%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%22%2C%0A%20%20%22elmType%22%3A%20%22div%22%2C%0A%20%20%22style%22%3A%20%7B%0A%20%20%20%20%22visibility%22%3A%20%22%3Dif(%5B%24PermMask%5D%26gt%3B%3D'0xb00'%2C'hidden'%2C'visible'%22%0A%20%20%7D%2C%0A%20%20%22txtContent%22%3A%20%22%3Dif(%5B%24PermMask%5D%26gt%3B%3D'0xb00'%2C'read-only'%2C'more%20than%20read')%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20a%20real%20life%20use%20case%2C%20I%20use%20this%20to%20show%20a%20%22Run%20flow%22%20button%20to%20only%20those%20users%2C%20who%20have%20at%20least%20an%20edit%20permission%20for%20the%20specific%20list%20item.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20hope%20this%20helps%20somebody%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3017542%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPermissions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Visitor

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 :)

0 Replies