2

I have a list where an item can have different statuses (Draft, Planned, Updated and finished) I wanted 3 different flows to be able to run, so the buttons are:

  • When Draft: [Send item]
  • When Updated: [Send Update]
  • When Planned: [Finish]
  • When Finished: Field is empty

I have a part code assembled from various sources, and this works perfectly, so I hope I can already help someone with this

{
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "txtContent": "Send Item",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"}"
      },
      "style": {
        "background-color": "#bf279b",
        "color": "white",
        "border-radius": "10px",
        "margin-top": "2px",
        "padding": "6px",
        "position": "absolute",
        "left": "0",
        "cursor": "pointer",
        "visibility": {
          "operator": "?",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "[$Status]",
                "Draft"
              ]
            },
            "visible",
            "hidden"
          ]
        }
      }
    },
    {
      "elmType": "button",
      "txtContent": "Send Update",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"}"
      },
      "style": {
        "background-color": "#279bbf",
        "color": "white",
        "border-radius": "20px",
        "margin-top": "2px",
        "padding": "6px",
        "position": "absolute",
        "left": "0",
        "cursor": "pointer",
        "visibility": {
          "operator": "?",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "[$Status]",
                "Updated"
              ]
            },
            "visible",
            "hidden"
          ]
        }
      }
    },
    {
      "elmType": "button",
      "txtContent": "Finish",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"}"
      },
      "style": {
        "background-color": "#279bbf",
        "color": "white",
        "border-radius": "20px",
        "margin-top": "2px",
        "padding": "6px",
        "position": "absolute",
        "left": "0",
        "cursor": "pointer",
        "visibility": {
          "operator": "?",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "[$Status]",
                "Planned"
              ]
            },
            "visible",
            "hidden"
          ]
        }
      }
    }
  ]
}

Now I want the last button (Finish) only appear when the end date has passed. So that condition needs to be [$Status] = "Planned" AND [$DateEnd] is "passed xx minutes ago".

The line I already got working on its own in the conditional formatting is this (15 minutes after EndDate the line gets a different color)

if([$DateEnd] <= (@now - 900000)

But I can't get these combined in my flow button json. Maybe in that code is also room for improvement or another way to accomplish this scenario?

Any help would more than appreciated.

1

Try changing visibility property in last code block to:

"visibility": "=if([$Status] == 'Planned' && [$DateEnd] <= (@now - 900000), 'visible', 'hidden')"

OR

"display": "=if([$Status] == 'Planned' && [$DateEnd] <= (@now - 900000), 'block', 'none')"
4
  • Hi Ganesh, thank you, that worked like a charm! The context seems much more easy also in this oneliner. I understand the logics far better with this. Is there any reason I would use the other way as in my example (with the operands)? I'm thinking of changing the rest of my code also following your example. (All the Json stuff is new for me) – Kris Bloemen Sep 24 '20 at 13:23
  • 1
    The format style you have used is called as "Abstract Syntax Tree(AST)" JSON. And as per this post, Column Formatting will be available in SharePoint 2019 as well, But the Excel-style expressions (like given in my answer) won’t be available. As you are using SharePoint Online, you can convert and easily use your JSON code in the format I mentioned in my answer without any problem. – Ganesh Sanap Sep 24 '20 at 16:55
  • Is it also possible to nest AND and OR? So you have the if time condition AND (Staus=planned OR Status=Paid) I've tried a lot, but nothing seemed to work: "visibility": "=if([$DateStart] <= (@now + 720000) && if([$Status] == 'Planned', 'visible', if([$Status] == 'Paiment received', 'visible', 'hidden')),'hidden')" "visibility": "=if([$DateStart] <= (@now + 720000) && [$Status] == 'Planned', 'visible', if([$DateStart] <= (@now + 720000) && [$Status] == 'Paiment received', 'visible', 'hidden'),'hidden')" – Kris Bloemen Dec 9 '20 at 13:19
  • 1
    Absolutely possible! Try this: "visibility": "=if([$DateStart] <= (@now + 720000) && ([$Status] == 'Planned' || [$Status] == 'Paiment received'), 'visible', 'hidden')". Hope this is what you are looking for or I need to understand more about your requrements/conditions. – Ganesh Sanap Dec 9 '20 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.