SOLVED

SharePoint Json If statement for visibility based on Other Colums being empty/ filled

Copper Contributor

I've been trying to create a SharePoint list in which a button is visible when two of the columns of that row have a value entered. I've tried looking for answers but can't find anything that has worked.

I'm trying to check that the column name Approvers for that item is not empty (for which I'm trying to check that it is not equal to null). Ideally I would like to check that Sender is not null but any help would be appreciated. Here's what my JSON file looks like:

 

{
"elmType": "button",
"txtContent": "Send",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"9de29813-f1b8-4ebc-870e-fe3a7a4472af\"}"
},
"style": {
"background-color": "purple",
"color": "white",
"visibility": "=if([$Approvers] == \"\" ,'hidden','visible')"
}
}
Stanislawo_0-1661249964610.png

As you can see the approvers field doesn't change the visibility. Any help would be much appreciated!!

 
7 Replies

@Stanislawo "visibility": "=if([$Approvers] == '' ,'hidden','visible')" where the =='' uses single quotes.

visibility.png

 

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

Thank you so much!! I'm a bit gutted that I didn't try that, do you know how I could incoroporate an and statement into the if statement? Exact same thing but for another column called senders.

@Stanislawo just add && [$Senders]=='' for and or use pipes || for or

 

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

@RobElliott Thanks a lot, I've this but unfortunately it looks like the date column always has a value, I tried finding what default value that may be but couldn't find anything. Here's a visual representation of the issue I've got:

Stanislawo_0-1661271308500.png

Here's the code too:

{
"elmType": "button",
"txtContent": "Send",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"9de29813-f1b8-4ebc-870e-fe3a7a4472af\"}"
},
"style": {
"padding": "0px 25px",
"cursor": "pointer",
"border": "none",
"color": "white",
"font-weight": "550",
"background-color": "#0078d4",
"text-decoration": "none",
"font-size": "14px",
"text-align": "center",
"width": "85px",
"visibility": "=if([$Approver] == '' || [$Sender] == '' || [$Deadline] == '','hidden','visible')"
}
}
 
I only want the button to show when all 3 values have been set but, SP seems to think that there's always a value under the date column. But maybe I've just coded it wrong. Any advice would be much appreciated!!

 

best response confirmed by Stanislawo (Copper Contributor)
Solution

@Stanislawo 

"visibility": "=if([$Approver] == '' && [$Sender]=='' && Number([$Deadline]) == 0 ,'hidden','visible')"
 
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

@Stanislawo There are couple of ways to check if date column is empty or not. 

 

One way suggested by @RobElliott using Number() function works well (+1).

 

Other ways are to use the toString() function OR directly refer to column name like ![$Deadline].

 

Check: SharePoint JSON formatting: Check if date & time column is blank/empty 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Fantastic! That's sorted it, thank you so much for the help!
1 best response

Accepted Solutions
best response confirmed by Stanislawo (Copper Contributor)
Solution

@Stanislawo 

"visibility": "=if([$Approver] == '' && [$Sender]=='' && Number([$Deadline]) == 0 ,'hidden','visible')"
 
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

View solution in original post