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.
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')"
}
}
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)
- rolanddaaneJun 20, 2021Copper 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')"
}
}- rolanddaaneJun 20, 2021Copper ContributorBTW, On the column Filename I have something similat, and that does work:
the filename is not allowed to have 2 minus signs (eg --)
The filename that's generated based on metadata from user is formatted like BC1234-BAM-XX-YY-ZZ-A-001.docx and all the elements must be present before someone can trigger the approval flow.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"color": "=if(indexOf(@currentField, '--' )<1, 'Green', if(indexOf(@currentField, '--' )>0, 'grey', 'black'))",
"font-size": "1.12em"
}
}- rolanddaaneJun 20, 2021Copper Contributor
I can't get this to work.
it looks like the if statement is ignored. If I change the order of visible and hidden the button either shows or is invisible regardless if ther is Yes in the evaluated column.
my 2 columns are simply 1 line of text. Is there maybe something I need to configure?
it's really a pitty because now the button shows on every row, even folders(where it shouldn't)