Forum Discussion
Sportback
Dec 11, 2021Copper Contributor
Sharepoint/Lists - Toggle if statement
Hi everyone,
This simple "if statement" does not work.
The toggle "NO to YES" works, but does not work "YES to NO"
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"customRowAction": {
"action": "setValue",
"actionInput": {
"Pay_x00e9_": "=if([$Paye] == 'YES', 'NO', 'YES')",
"Payerpar": "@me"
}
}
}
Thanks
Sportback I am able to update choice column as well. Here's JSON I am using:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "customRowAction": { "action": "setValue", "actionInput": { "Paye": "=if([$Paye] == 'OUI', 'NON', 'OUI')" } }, "children": [ { "elmType": "button", "attributes": { "class": "ms-bgColor-purple--hover ms-fontColor-white--hover ms-fontColor-gray140 ms-bgColor-gray30" }, "txtContent": "PAYER", "style": { "padding": "2px 15px 13px 15px", "height": "23px", "border": "none", "border-radius": "8px", "cursor": "pointer", "box-shadow": "rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px" } } ] }
Output:
Choice column settings:
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.
Sportback If [$Paye] column is of type "Yes/No", use JSON like below:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "customRowAction": { "action": "setValue", "actionInput": { "Pay_x00e9_": "=if([$Paye], false, true)", "Payerpar": "@me" } } }
Make sure you are using correct internal names of columns in JSON. Follow this article to get the internal name of your SharePoint column: How to find the Internal name of columns in SharePoint Online?
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
- SportbackCopper Contributor
Hi ganeshsanap
In fact, that works fine with type "Yes/No", but I want to use type "Choice" and that it does not work . That is not a problem with column name, because that it works when statement is "false"
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "customRowAction": { "action": "setValue", "actionInput": { "Pay_x00e9_": "=if([$Paye] == 'OUI', 'NON', 'OUI')", "test": "=if([$test] == true, false, true)", "Payerpar": "@me" } }, "children": [ { "elmType": "button", "attributes": { "class": "ms-bgColor-purple--hover ms-fontColor-white--hover ms-fontColor-gray140 ms-bgColor-gray30" }, "txtContent": "PAYER", "style": { "padding": "2px 15px 13px 15px", "height": "23px", "border": "none", "border-radius": "8px", "cursor": "pointer", "box-shadow": "rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px" } } ] }
Sportback I am able to update choice column as well. Here's JSON I am using:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "customRowAction": { "action": "setValue", "actionInput": { "Paye": "=if([$Paye] == 'OUI', 'NON', 'OUI')" } }, "children": [ { "elmType": "button", "attributes": { "class": "ms-bgColor-purple--hover ms-fontColor-white--hover ms-fontColor-gray140 ms-bgColor-gray30" }, "txtContent": "PAYER", "style": { "padding": "2px 15px 13px 15px", "height": "23px", "border": "none", "border-radius": "8px", "cursor": "pointer", "box-shadow": "rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px" } } ] }
Output:
Choice column settings:
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.