Forum Discussion

SG523's avatar
SG523
Brass Contributor
Feb 22, 2022

SharePoint Json If statement for visibility

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
  • 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:

     

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

  • RobElliott's avatar
    RobElliott
    Silver Contributor

    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:

     

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

    • SG523's avatar
      SG523
      Brass Contributor
      That works perfectly! I didn't know there was a visibility property!

      Thank you!

Resources