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.
{
"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.
- KjoniXAug 05, 2024Copper Contributor
Maruthi Gadde Peter_K rolanddaane RobElliott evaristo1904
I use the same method as you to run a flow. The flow pane pop up to the left, user click run, but the button is still visible until page manually refresh (and the approval status is changed by the flow).
I want to show users that the flow is started, it could be have a visibility check that remove button, column with status "sent for approval" etc.
If json formatting could handle two action it has not been any problem, executeflow and setvalue, but as far as I understand it just handle one action.
- Peter_KApr 18, 2019Copper Contributor
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...
- MatsWarnolfAug 29, 2019Copper Contributor
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.