带有流按钮的 SharePoint 列表列的条件格式

Conditional formatting on SharePoint list column with Flow buttons

我正在尝试添加一个按钮,以有条件地在 SharePoint 列表的项目上启动流程。

我有一个包含多个列的列表,例如 StatusApprovalCreated_By。我希望 Approval 列显示可以在列表项上启动 Power Automate Flow 的按钮。这些按钮在以下情况下应该有所不同:

  1. Status 列中的字段等于 'Draft' -> 显示启动流程 1 的按钮
  2. Status 列中的字段等于 'Approved' -> 显示启动流程 2 的按钮
  3. 当查看列表的人不是项目的创建者时 -> 不显示按钮

可以找到使用格式化列来包含启动流程的按钮的方法 here。但是该示例不包含条件语句,请参见下面的代码:

{
  "$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"
    }
  ]
}

我发现可以在 JSON 代码中包含 if 语句。可以使用以下代码检查 Status"=if([$Status] == 'Approved','','')".

查看列表的人是否与创建项目的人相同应该可以用这样的东西来检查(尽管这段特定的代码不起作用..):"=if(@me == [$Created_x0020_By.email],'','')"

我不太了解 JSON,所以我不知道如何将这些条件插入到上面的代码中。所以我想请你帮忙!


感谢 Michael Han_MSFT 解决了!我的结果代码是:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "=if(@me == [$Author.email], if([$Status]=='Draft', '{\"id\": \"d4ebc660-16fd-4320-a69c-d91d51277666\"}', if([$Status]=='Approved', '{\"id\": \"94233841-9c32-4e90-9018-479e72c33385\"}', 'null')), 'null')"
  },
  "attributes": {
    "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
  },
  "style": {
    "border": "none",
    "background-color": "transparent",
    "cursor": "pointer"
  },
  "children": [
    {
      "elmType": "span",
      "attributes": {
        "iconName": "=if(@me == [$Author.email],'Flow','')"
      },
      "style": {
        "padding-right": "6px"
      }
    },
    {
      "elmType": "span",
      "txtContent": "=if(@me == [$Author.email], if([$Status]=='Draft','Start approval', if([$Status]=='Approved','Cancel', '')), '')"
    }
  ]
}

1.The Statu可以在"actionParams"中用下面的代码检查,不同的流不同的id:

"actionParams": "=if([$Status]=='Approved','{\"id\": \"a04b0180-7d32-471c-8ff6-49497d229b23\"}','{\"id\": \"1f922b63-a66b-4177-9aa6-f4c37c4d6f27\"}')"

2.You 需要使用 [$Author.email] 而不是 [$Created_x0020_By.email].

以下示例代码供您参考:

    {
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "=if([$Status]=='Approved','{\"id\": \"a04b0180-7d32-471c-8ff6-49497d229b23\"}','{\"id\": \"1f922b63-a66b-4177-9aa6-f4c37c4d6f27\"}')"
  },
  "attributes": {
    "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
  },
  "style": {
    "border": "none",
    "background-color": "transparent",
    "cursor": "pointer"
  },
  "children": [
    {
      "elmType": "span",
      "attributes": {
        "iconName": "=if(@me == [$Author.email],'Flow','')"
      },
      "style": {
        "padding-right": "6px"
      }
    },
    {
      "elmType": "span",
      "txtContent": "=if(@me == [$Author.email], if([$Status]=='Approved','Flow1','Flow2'), '')"
    }
  ]
}

测试结果: