Forum Discussion
Conditional JSON formatting of button in SharePoint List
- Apr 18, 2019
{
"elmType": "button",
"txtContent": "Get Approved",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\":\"86dfdf10-8d99-4914-8e98-fe4b21ed7e34\"}"
},
"style": {
"background-color": "purple",
"color": "white",
"visibility": "=if(([$ModerationStatus] == 'Pending') && ([$DocumentType] == 'Offer'),'visible','hidden')"
}}
check this sample .. I got rid of the Operator and used a simple if statement. only change to visibility property.
Thank you, that is exactly what I was looking for.
Only one more thing: can i put multiple values in my if condition?
I want the button to be visible if:
ModerationStatus = pending
Documenttyp = Offer OR Schedule OR List...
I have exactly that question. My problem is that my organization is multilingual.
I display the button only when _ModerationStatus is draft and I have a flow that takes care of the rest.
But the text content of _ModerationStatus is language specific. So for swedes, the draft status is called "Utkast". I also have other languages to check for.
I have been experimenting with that line above:
"visibility": "=if(([$_ModerationStatus] == 'Draft')'visible','hidden')"
But I cannot grasp how to make more values match for it to be visible. The obvious solution is that if the value was numeric, it would be language independent..
- MatsWarnolfAug 29, 2019Copper Contributor
I found the solution here https://sharepoint.stackexchange.com/questions/260974/column-formatting-and-or-conditions
So my line is this:
"visibility": "=if([$_ModerationStatus] == 'Utkast','visible',if([$_ModerationStatus] == 'Draft','visible','hidden')"
This seems to do the trick.
The basic syntax for if is this: (taken straight from Stack Exchange)
if(Condition, ResultIfTrue,ResultIfFalse)
//OR (like you have it) if( condition1, resultIfTrue, if( condition2, result-If-c1-False-And-C2-True result-If-c1-False-And-C2-false ) ) //So, here's the AND: if( condition1, if( condition2, result-If-c1-true-And-C2-True result-If-c1-true-And-C2-false ), result-if-c1-false
So big thanks to Maruthi Gadde for giving me a BIG piece of the puzzle and to Stevish over at Stack Exchange for providing me with the last and final piece.
- evaristo1904Mar 20, 2021Copper Contributor
Hi MatsWarnolf
not sure if I understood your solution... or at least with me it doesn't work:
I want to show the Flow button only if the STATUS column is NOT OK and if the ELLEGIBLE FOR APPROVAL column is Yes.{"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json","elmType": "button","txtContent": "Get approval","customRowAction": {"action": "executeFlow","actionParams": "{\"id\": \"99934f4d-182a-4aad-8b78-08a6b3c9727e\"}"},"style": {"background-color": "green","color": "white","visibility": "if([$Status]=='NOT OK','visible',if([$Elegibleforapproval]=='Yes','visible','hidden'))"}}Can you help sort it out what am I doing wrong?? Thanks!- RobElliottMar 20, 2021Silver Contributor
evaristo1904 The way you've got the visibility line at the moment the if statement is saying if the status column is equal to Yes then visible, but if the Status column is not equal to Yes then if the EligibleforApproval column is equal to Yes then visible, otherwise hidden. That's not correct and not what you're trying to achieve.
You need to be using && for the and as follows:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "button", "txtContent": "Get approval", "customRowAction": { "action": "executeFlow", "actionParams": "{\"id\": \"d0a539c4-cb12-4873-a2d7-7150882e4235\"}" }, "style": { "background-color": "#f14717", "color": "#ffffff", "outline": "transparent", "border-width": "1px", "border-style": "solid", "border-color": "transparent", "cursor": "pointer", "font-size": "12px", "visibility": "=if(([$Status] == 'Not OK') && ([$EligibleforApproval] == 'Yes'),'visible','hidden')" } }
As you can see it's a much more simple syntax and is easier to get right. So the result below only shows the button where the Status = Not Ok and EligibleforApproval =Yes
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.