0

What I would like is to create a button from the choice column. So the user can not select a choice by himself. But triggers a power automate flow by pressing on the button. So how can I turn a choice column into a button. I tried for hours in JSON. But no luck:

This is the JSON of the choice column:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "flex-wrap": "wrap",
    "display": "flex"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "box-sizing": "border-box",
        "padding": "4px 8px 5px 8px",
        "overflow": "hidden",
        "text-overflow": "ellipsis",
        "display": "flex",
        "border-radius": "16px",
        "height": "24px",
        "align-items": "center",
        "white-space": "nowrap",
        "margin": "4px 4px 4px 4px"
      },
      "attributes": {
        "class": {
          "operator": ":",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "@currentField",
                "Niet verzonden"
              ]
            },
            "sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall sp-css-color-CornflowerBlueFont",
            {
              "operator": ":",
              "operands": [
                {
                  "operator": "==",
                  "operands": [
                    "@currentField",
                    "Aangevraagd"
                  ]
                },
                "sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont",
                {
                  "operator": ":",
                  "operands": [
                    {
                      "operator": "==",
                      "operands": [
                        "@currentField",
                        "Goedgekeurd"
                      ]
                    },
                    "sp-css-backgroundColor-BgGold sp-field-fontSizeSmall sp-css-color-GoldFont",
                    {
                      "operator": ":",
                      "operands": [
                        {
                          "operator": "==",
                          "operands": [
                            "@currentField",
                            ""
                          ]
                        },
                        "",
                        {
                          "operator": ":",
                          "operands": [
                            {
                              "operator": "==",
                              "operands": [
                                "@currentField",
                                "Afgekeurd"
                              ]
                            },
                            "sp-css-backgroundColor-BgCoral sp-field-fontSizeSmall sp-css-color-CoralFont",
                            "sp-field-borderAllRegular sp-field-borderAllSolid sp-css-borderColor-neutralSecondary"
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      },
      "txtContent": "@currentField"
    }
  ]
}
3
  • Can you share screenshot/image of expected behavior is possible? What should be the text on button? How many buttons to show in column? Is there anything else you are doing using the flow or only settings the same column value (I can suggest workaround if you want to update current column value only)? Commented Oct 18, 2023 at 10:36
  • The choice column should only show one button. So the user can not change the value of the choice column because its a button. That button triggers a power automate flow that shows a microsoft form where the user can enter his value. The power automate changes the value of the choice column depending on the value the user has enter in the microsoft form. Commented Oct 18, 2023 at 10:46
  • Then why you need JSON provided in your question? It only changes "class" based on the choice value. Try using the JSON similar to the JSON given in my answer below. Commented Oct 18, 2023 at 10:59

1 Answer 1

1

You can create a button using SharePoint JSON column formatting which can trigger a Power automate flow.

Example:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\": \"edf627d9-20f4-45ba-8bc9-4494bf2ff1be\"}"
  },
  "attributes": {
    "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
  },
  "style": {
    "border": "none",
    "background-color": "transparent",
    "cursor": "pointer"
  },
  "children": [
    {
      "elmType": "span",
      "attributes": {
        "iconName": "Flow"
      },
      "style": {
        "padding-right": "6px"
      }
    },
    {
      "elmType": "span",
      "txtContent": "Send to Manager"
    }
  ]
}

Where edf627d9-20f4-45ba-8bc9-4494bf2ff1be is the ID for your Power automate flow. You can change the border, background-color, etc. styling as per your requirements.

Output:

enter image description here

Reference: Create a button to launch a Flow using SharePoint JSON formatting

1
  • 1
    Thank you that will help Commented Oct 18, 2023 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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