Apr 16 2019 11:22 PM
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
Apr 18 2019 12:07 AM
Solution
{
"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.
Apr 18 2019 01:13 AM
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...
Aug 29 2019 03:13 AM
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..
Aug 29 2019 06:17 AM
I found the solution here https://sharepoint.stackexchange.com/questions/260974/column-formatting-and-or-conditions
So my line is this:
"visibility": "=if([$_ModerationStatus] == 'Utkast','visible',if([$_ModerationStatus] == 'Draft','visible','hidden')"
This seems to do the trick.
The basic syntax for if is this: (taken straight from Stack Exchange)
if(Condition, ResultIfTrue,ResultIfFalse)
//OR (like you have it)
if(
condition1,
resultIfTrue,
if(
condition2,
result-If-c1-False-And-C2-True
result-If-c1-False-And-C2-false
)
)
//So, here's the AND:
if(
condition1,
if(
condition2,
result-If-c1-true-And-C2-True
result-If-c1-true-And-C2-false
),
result-if-c1-false
So big thanks to @Maruthi Gadde for giving me a BIG piece of the puzzle and to Stevish over at Stack Exchange for providing me with the last and final piece.
Mar 20 2021 03:14 AM - edited Mar 20 2021 03:15 AM
Hi @MatsWarnolf
not sure if I understood your solution... or at least with me it doesn't work:
Mar 20 2021 07:13 AM
@evaristo1904 The way you've got the visibility line at the moment the if statement is saying if the status column is equal to Yes then visible, but if the Status column is not equal to Yes then if the EligibleforApproval column is equal to Yes then visible, otherwise hidden. That's not correct and not what you're trying to achieve.
You need to be using && for the and as follows:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"txtContent": "Get approval",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"d0a539c4-cb12-4873-a2d7-7150882e4235\"}"
},
"style": {
"background-color": "#f14717",
"color": "#ffffff",
"outline": "transparent",
"border-width": "1px",
"border-style": "solid",
"border-color": "transparent",
"cursor": "pointer",
"font-size": "12px",
"visibility": "=if(([$Status] == 'Not OK') && ([$EligibleforApproval] == 'Yes'),'visible','hidden')"
}
}
As you can see it's a much more simple syntax and is easier to get right. So the result below only shows the button where the Status = Not Ok and EligibleforApproval =Yes
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.
Mar 20 2021 10:08 AM
Jun 20 2021 05:34 AM
Jun 20 2021 06:32 AM
@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)
Jun 20 2021 08:17 AM
Jun 20 2021 08:37 AM
Jun 20 2021 12:55 PM
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)