SOLVED

How can users change Yes/No columns?

Copper Contributor

What are the different ways I can tell my users how to change the value of a custom Yes/No column in the browser? It looks like my options are to tell them to either check the circle in the far left column that selects the item, and then scroll down the the item's properties and check or uncheck that option (although this seems to fail sometimes for me and I don't get much of an error message) or use grid view the check or uncheck the column. Similarly in the latter option I often get an error that says the file is locked by me, even though the file is not open anywhere in my session.

 

Are there any other options or settings I could use to make it a little easier on users?

8 Replies

@dgajohnson Try using JSON column formatting for your Yes/No column like below: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "inlineEditField": "@currentField",
  "txtContent": "=if(@currentField,'Yes','No')"
}

 

This will allow users to edit the column value inline from list/table view itself without going to properties form: 

ganeshsanap_0-1681286706744.png


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.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

@ganeshsanap thank you, this is working!


Do you know of a way to make it so that you can change the value with only one click? With this formatting the user has to click the cell, wait for it to load, and then change its value. Do you know of a method where the user could change the value with just one click?

best response confirmed by dgajohnson (Copper Contributor)
Solution

@dgajohnson try using JSON sample given here: Yes/No Column Toggle screenshot (1).gif


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.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

@ganeshsanap thanks! I found that one too. I ended up using this:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "=if(@currentField, 'Yes', 'No')",
  "customRowAction": {
    "action": "setValue",
    "actionInput": {
      "MyCustomField": "=if(@currentField, false, true)"
    }
  },
  "style": {
    "background-color": "=if(@currentField, '#0078d4', '#ffffff')",
    "color": "=if(@currentField, '#ffffff', '#333333')",
    "border": "none",
    "cursor": "pointer",
    "padding": "4px 12px",
    "border-radius": "4px"
  }
}

ChatGPT made the style, and I pulled the customRowAction parameter from that repo.

@ganeshsanap 

 

Is there a way to adjust this code to have it only apply to certain content types and/or apply only if another column meets a requirement?

My problem:

I have a Sharepoint list which contains both folders and excel files. With the current JSON, it automatically applies the pre-set value to all entities in the list where I only want it to show next to the excel files to avoid confusion.

Screenshot 2023-11-27 170630.png

@sam77meyer Yes, you can hide the JSON formatting for folders using visibility or display properties inside style property.

 

Example: 

 

"style": {
    "visibility": "=if([$ContentType] == 'Folder', 'hidden', 'visible')"
},

 

Where ContentType is the internal name of your SharePoint list column which you have to use in this format: [$ContentType]. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

 

You may have to show the Content Type column in your library view to read it's value in JSON.

 

Above JSON snippet is taken from here (full JSON example available): SharePoint Online: Download files using JSON Formatting 


Please consider giving a Like if my post helped you in any way.

Thanks for the reply @ganeshsanap 

 

Still having trouble after using the following JSON - only change I can get using variations of this code is it hiding the Yes/No for every content type.

 

Screenshot 2023-11-28 115220.png

Solved: Because it was reading the style script it showed nothing because I did not have any base style attributes listed. Working now
1 best response

Accepted Solutions
best response confirmed by dgajohnson (Copper Contributor)
Solution

@dgajohnson try using JSON sample given here: Yes/No Column Toggle screenshot (1).gif


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.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

View solution in original post