SOLVED

SharePoint Json If statement for visibility

%3CLINGO-SUB%20id%3D%22lingo-sub-3200046%22%20slang%3D%22en-US%22%3ESharePoint%20Json%20If%20statement%20for%20visibility%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3200046%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20column%20in%20a%20SP%20library%20with%20the%20following%20Json.%20I'm%20wondering%20if%20there%20is%20a%20way%20to%20make%20the%20button%20%22hidden%22%20and%20not%20clickable%20based%20on%20another%20column%3F%20I%20need%20this%20button%20to%20only%20show%20and%20be%20clickable%20in%20rows%20where%20the%20column%20%5B%24ApprovalLink%5D%20is%20not%20None.%20I%20imagine%20something%20like%20an%20IF%20that%20applies%20the%20Json%20if%20Approval%20Link%20is%20not%20None%20but%20if%20it%20is%20None%20if%20just%20makes%20it%20blank%20or%20act%20blank%3F%20Is%20this%20possible%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22%24schema%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%3C%2FA%3E%22%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22elmType%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22button%22%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22customRowAction%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22action%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22executeFlow%22%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22actionParams%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22%7B%5C%22id%5C%22%3A%20%5C%221111111111%5C%22%7D%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22attributes%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22class%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22ms-fontColor-themePrimary%20ms-fontColor-white%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22style%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22border%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22none%22%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22border-radius%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%220%2010px%22%3C%2FSPAN%3E%3CSPAN%3E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%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22padding-left%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%226px%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22elmType%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22span%22%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22txtContent%22%3C%2FSPAN%3E%3CSPAN%3E%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22%3D'Reminder%20to%20'%2B%5B%24ApproverEmail%5D%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%5D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EThanks%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3202544%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Json%20If%20statement%20for%20visibility%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3202544%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1310219%22%20target%3D%22_blank%22%3E%40SG523%3C%2FA%3E%26nbsp%3Bthere's%20a%20simpler%20JSON%20code%20that%20you%20can%20use%20and%20where%20you%20set%20the%20%3CSTRONG%3Evisibility%3C%2FSTRONG%3E%20property%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%22%2C%0A%20%20%22elmType%22%3A%20%22button%22%2C%0A%20%20%22txtContent%22%3A%20%22Publish%20to%20Teams%22%2C%0A%20%20%22customRowAction%22%3A%20%7B%0A%20%20%20%20%22action%22%3A%20%22executeFlow%22%2C%0A%20%20%20%20%22actionParams%22%3A%20%22%3D'%7B%5C%22id%5C%22%3A%5C%22021ec4e0-8f85-46b3-a557-a4456960a4eb%5C%22%2C%20%5C%22headerText%5C%22%3A%5C%22Publish%20'%20%2B%20%5B%24Title%5D%20%2B%20'%5C%22%2C%5C%22runFlowButtonText%5C%22%3A%5C%22Publish%20now%5C%22%7D'%22%0A%20%20%7D%2C%0A%20%20%22style%22%3A%20%7B%0A%20%20%20%20%22background-color%22%3A%20%22%23008082%22%2C%0A%20%20%20%20%22color%22%3A%20%22white%22%2C%0A%20%20%20%20%22border-radius%22%3A%20%2210px%22%2C%0A%20%20%20%20%22visibility%22%3A%20%22%3Dif(%5B%24PublishedToTeams%5D%20%3D%3D%20'Yes'%2C'hidden'%2C'visible')%22%0A%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20result%20is%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22buttonVisibility2.png%22%20style%3D%22width%3A%20463px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350615i8A06F35D45009C43%2Fimage-dimensions%2F463x146%3Fv%3Dv2%22%20width%3D%22463%22%20height%3D%22146%22%20role%3D%22button%22%20title%3D%22buttonVisibility2.png%22%20alt%3D%22buttonVisibility2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERob%3CBR%20%2F%3ELos%20Gallardos%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23006400%22%3EIntranet%2C%20SharePoint%20and%20Power%20Platform%20Manager%20(and%20classic%201967%20Morris%20Traveller%20driver)%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3203834%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Json%20If%20statement%20for%20visibility%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3203834%22%20slang%3D%22en-US%22%3EThat%20works%20perfectly!%20I%20didn't%20know%20there%20was%20a%20visibility%20property!%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you!%3C%2FLINGO-BODY%3E
Contributor

Hello,

 

I have a column in a SP library with the following Json. I'm wondering if there is a way to make the button "hidden" and not clickable based on another column? I need this button to only show and be clickable in rows where the column [$ApprovalLink] is not None. I imagine something like an IF that applies the Json if Approval Link is not None but if it is None if just makes it blank or act blank? Is this possible?

 

{
"elmType": "button",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"1111111111\"}"
},
"attributes": {
"class": "ms-fontColor-themePrimary ms-fontColor-white"
},
"style": {
"border": "none",
"border-radius": "0 10px",
"background-color": "Orange",
"cursor": "pointer"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "mail"
},
"style": {
"padding-right": "6px",
"padding-left": "6px"
}
},
{
"elmType": "span",
"txtContent": "='Reminder to '+[$ApproverEmail]"
}
]
}
 
Thanks
2 Replies
best response confirmed by SG523 (Contributor)
Solution

@SG523 there's a simpler JSON code that you can use and where you set the visibility property:

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "Publish to Teams",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "='{\"id\":\"021ec4e0-8f85-46b3-a557-a4456960a4eb\", \"headerText\":\"Publish ' + [$Title] + '\",\"runFlowButtonText\":\"Publish now\"}'"
  },
  "style": {
    "background-color": "#008082",
    "color": "white",
    "border-radius": "10px",
    "visibility": "=if([$PublishedToTeams] == 'Yes','hidden','visible')"
  }
}

 

The result is:

buttonVisibility2.png

 

Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

That works perfectly! I didn't know there was a visibility property!

Thank you!