Forum Discussion
Conditional JSON formatting of button in SharePoint List
Hi everybody
I am looking for a solution for a formatting problem in one of my sharepoint columns.
In one column I have a button which triggers a flow.
I am aiming for a visability of the button in correlation of two other columns. I have allready achieved to make the button visible if the approval status is pending and hide it if the approval status is approved or rejected.
However I want the visibility to be dependend on another column (choice field) as well. In this column my users can choose document types (offer, report, ...)
My goal is to only make this button visible for special document types and an approval status=pending.
Currently I am using this formatting in JSON:
{
"elmType": "button",
"txtContent": "Version freigeben",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"#\"}"
},
"style": {
"border": "none",
"background-color": "blue",
"color": "#ffffff",
"cursor": "pointer",
"visibility": {
"operator": "?",
"operands": [
{
"operator": "==",
"operands": [
"[$_ModerationStatus]",
"Pending"
]
},
"visible",
"hidden"
]
}
}
}
My goal is to ad another condition to the visibility, unfortunatley I don't know how this is done.
Thanks in advance
Peter
{
"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.
13 Replies
- rolanddaaneCopper ContributorHi,
I'm trying something similar, but can't get it to work.
I want the button to show if the value of column ShareBim360 = Yes.
In my case it's just ignoring and showing on every row.....
Any ideas?
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"txtContent": "Share to Bim360",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"bce75e04-998b-4600-b829-7370d6a2ee15\"}"
},
"style": {
"background-color": "#468259",
"color": "white",
"visibility": "=if(([$ShareBim360] == 'Yes'),'hidden','visible')"
}
}- RobElliottSilver Contributor
rolanddaane your if statement on the visibility line is the wrong way round, it should be:
"visibility": "=if(([$ShareBim360] == 'Yes'),'visible', 'hidden')"Rob
Los Gallardos
Intranet, SharePoint, Website and Power Platform Manager (and classic 1967 Morris Traveller driver)- rolanddaaneCopper ContributorHi mate, thanks!
I took an example of yours, and I really like the buttons!
If I use the below the buttons shoe on no line, even if the value of ShareBim360 contains Yes
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"txtContent": "Share to Bim360",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"bce75e04-998b-4600-b829-7370d6a2ee15\",\"headerText\":\"All Things REI\",\"runFlowButtonText\":\"Publish Now\"}"
},
"style": {
"background-color": "#008082",
"color": "white",
"border-radius": "0 15px",
"visibility": "=if(([$ShareBim360] == 'Yes'),'visible', 'hidden')"
}
}
- Maruthi GaddeIron Contributor
{
"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.
- KjoniXCopper 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_KCopper 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...
- MatsWarnolfCopper 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..