1

Hope someone will be able to help me on this.

I'm looking for a way to disable (having it read only) a List column using some JSON formatting.

I know I can do it using additional calculated columns but I don't want to do this cause I have several columns and that will be too much.

Few years ago, I saw someone doing it with JSON code, something like:

{
  "elmType": "div",
  "txtContent": "@currentField"
}

I know there's something missing in there but I don't remember what.

Does anyone have an idea how to do this ?

  • What do you mean by disabling list column? You don't want users to edit this field or is it link type column and you don't want your users to click on it? what is the data type of your column? – Ganesh Sanap Jul 6 at 15:38
  • List formatting will only affect the display and has no effect on the writability (or even the display on the form) of fields – theChrisKent Jul 6 at 15:39
  • @theChrisKent: I understand what you say but i know the guy did it, he changed something in the code sample up there. and the field became read only. i just don't remember who the guy was and i don't know anyone anymore in that company. – Kaddrik Jul 6 at 15:47
  • @GaneshSanap: My columns are text. I mean having the column like "read only" . As if you were trying to type into a calculated field. i don't want the users to edit the fields. I know the downside was the fields were still editable in the form but back then, i removed them from the form. – Kaddrik Jul 6 at 15:47
  • 1
    Hi @theChrisKent, thanks for your answer. I watched this video before creating the post. Well ok then :-( that means i'll have to create additional columns. thanks for your time ! have a great day – Kaddrik Jul 7 at 6:10
0

As a workaround,you could use pnp powershell to set column read only.

$username = "amos@contoso.onmicrosoft.com"
$password = "Password"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)

Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/dev -Credentials $cred
 
# Get Context
$clientContext = Get-PnPContext
 
# -List: The list object or name of the list
# -Identity: The field object or name
$targetField = Get-PnPField -List "test_test" -Identity "unClickable"
 
# Make list column required
$targetField.ReadOnlyField = 1   
   
$targetField.Update()
 
$clientContext.ExecuteQuery()
 
Disconnect-PnPOnline
| improve this answer | |
  • Hi @Amos_MSFT, Thanks a lot for your answer. This is great ! but... I'm working for a pretty big financial institution and our laptops are restricted for lots of things. I won't be able to do this. I finally used calculated fields to do the trick, i don't really like it but...well. Anyway, i'll mark your solution as accepted in case it's of any help for someone else...or for me in the future. Thanks again !! – Kaddrik Jul 7 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.