8
n8n 中文网amn8n.com

完成Awork任务前检查依赖关系(变通方案)

高级

这是一个IT Ops领域的自动化工作流,包含 44 个节点。主要使用 If, Set, Code, Filter, Webhook 等节点。 完成Awork任务前检查依赖关系(变通方案)

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证

分类

工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "93fb8727a95622f4aa18b433e7f50b3d9eefa47fbe8901532956ded5db485301"
  },
  "nodes": [
    {
      "id": "8743a397-a6ca-4325-b0f8-33a34e15b63a",
      "name": "加载任务依赖项",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1600,
        -400
      ],
      "parameters": {
        "url": "=https://api.awork.com/api/v1/tasks/{{ $('Webhook call by Awork').item.json.body.entity.id }}/taskdependencies",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "9d0FyCu0IlwrdNkM",
          "name": "Awork Api"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "alwaysOutputData": true,
      "waitBetweenTries": 2000
    },
    {
      "id": "d3ac4527-eb09-49f5-9bff-7d83e494022d",
      "name": "聚合任务依赖项",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1800,
        -400
      ],
      "parameters": {
        "options": {
          "mergeLists": true
        },
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "renameField": true,
              "outputFieldName": "taskDependencies",
              "fieldToAggregate": "predecessorId"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1b05f8f7-9451-481d-b2cb-b74c4048f9e0",
      "name": "工作流配置",
      "type": "n8n-nodes-base.set",
      "position": [
        -640,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "20b87314-585f-4b03-a87d-cc1b9ff1f9c2",
              "name": "finishedStateLabels",
              "type": "array",
              "value": "=[\"Fertig\",\"Total fertig\"]"
            },
            {
              "id": "16f603e2-3703-4f47-a1b9-92503eb1ea43",
              "name": "useDependencies",
              "type": "boolean",
              "value": false
            },
            {
              "id": "ffd4703d-be65-4c35-b28c-6cafb1050d13",
              "name": "useTreeStructure",
              "type": "boolean",
              "value": true
            },
            {
              "id": "6adacba5-463e-4d5e-9571-54f1a026cb4d",
              "name": "addComments",
              "type": "boolean",
              "value": true
            },
            {
              "id": "a06d3f03-8c2d-4788-b986-4bfc2b2a37c5",
              "name": "commentTextDependencies",
              "type": "string",
              "value": "Some dependencies not yet finished! Status rolled back!"
            },
            {
              "id": "68e0a3f8-5b43-4b1c-b7c8-174abd4c3754",
              "name": "commentTextTreeStructure",
              "type": "string",
              "value": "Some child tasks not yet finished! Status rolled back!"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a610af8c-a4eb-4fa0-987f-8c001f78de20",
      "name": "获取任务变更",
      "type": "n8n-nodes-base.set",
      "position": [
        -220,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d1e893cd-bdeb-4c9b-8fe0-82dc11c047a7",
              "name": "=changes",
              "type": "array",
              "value": "={{ $('Webhook call by Awork').item.json.body.changes }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "72b495ae-fd9c-4347-ae17-8ba93a3afeb9",
      "name": "分离任务变更",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "changes"
      },
      "typeVersion": 1
    },
    {
      "id": "a4ec9460-d622-4d4b-a31b-ba3705faa88f",
      "name": "过滤任务状态变更",
      "type": "n8n-nodes-base.filter",
      "position": [
        220,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "82923633-648e-4ef0-82dc-cbe35de925b3",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.property }}",
              "rightValue": "TaskStatusId"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "cc8d6540-122e-48e0-bcf7-91331eea11d4",
      "name": "检查任务是否完成",
      "type": "n8n-nodes-base.if",
      "position": [
        620,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e4e5890b-588e-41f1-95c1-02e313fda09a",
              "operator": {
                "type": "array",
                "operation": "contains",
                "rightType": "any"
              },
              "leftValue": "={{ $('Workflow config').item.json.finishedStateLabels }}",
              "rightValue": "={{ $('Webhook call by Awork').item.json.body.entity.taskStatus.name }}"
            },
            {
              "id": "97e159ef-21df-4d1c-bef0-fc7a64ffa0fe",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Webhook call by Awork').item.json.body.entity.taskStatus.type }}",
              "rightValue": "done"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0b19f6d1-2821-49ff-8291-933c26165e93",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1940,
        -660
      ],
      "parameters": {
        "width": 880,
        "height": 1440,
        "content": "## Awork 对有子任务或依赖项已完成任务的变通方案"
      },
      "typeVersion": 1
    },
    {
      "id": "521684a2-f6d7-483a-aa73-bc6243d6bc33",
      "name": "Awork 的 Webhook 调用",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -940,
        0
      ],
      "webhookId": "57b88b94-6228-4e49-897d-64bf8c7d32db",
      "parameters": {
        "path": "57b88b94-6228-4e49-897d-64bf8c7d32db",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "00e9ea34-8110-43a4-a0a3-6d95272b7f22",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -740,
        -100
      ],
      "parameters": {
        "color": 4,
        "width": 360,
        "height": 280,
        "content": "### 工作流配置"
      },
      "typeVersion": 1
    },
    {
      "id": "ae4ad465-18d5-4a8b-b3ea-05aa9b8d81e3",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -260,
        -100
      ],
      "parameters": {
        "color": 4,
        "width": 660,
        "height": 280,
        "content": "### 从 webhook 调用有效负载中提取状态更改"
      },
      "typeVersion": 1
    },
    {
      "id": "124b4dc0-cc8b-4b10-89c0-fc3db5aa18bf",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        -100
      ],
      "parameters": {
        "color": 3,
        "width": 380,
        "height": 280,
        "content": "### 检查任务状态当前是否为\"已完成\""
      },
      "typeVersion": 1
    },
    {
      "id": "901b5649-3e43-4b03-9c2a-6281ec14cd3d",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1000,
        -100
      ],
      "parameters": {
        "color": 3,
        "width": 380,
        "height": 280,
        "content": "### 检查是否启用了依赖项"
      },
      "typeVersion": 1
    },
    {
      "id": "72cf9e1b-26f4-4132-b760-1b46f5348948",
      "name": "检查是否启用了依赖项",
      "type": "n8n-nodes-base.if",
      "position": [
        1140,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "53d5f2be-2830-4977-a69f-a0d135ea76c4",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Workflow config').item.json.useDependencies }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "1475c9e1-d99b-434c-b1e3-8160d25bd834",
      "name": "加载所有链接的任务",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2260,
        -400
      ],
      "parameters": {
        "url": "=https://api.awork.com/api/v1/me/projecttasks",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "filterby",
              "value": "={{ $json.taskDependencies.join(' or ') }}"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "9d0FyCu0IlwrdNkM",
          "name": "Awork Api"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "alwaysOutputData": true,
      "waitBetweenTries": 2000
    },
    {
      "id": "4d41c9a6-edae-4a0f-8a06-64c647d4da1a",
      "name": "构建过滤器参数",
      "type": "n8n-nodes-base.code",
      "position": [
        2020,
        -400
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  for( var key in item.json.taskDependencies ) {\n  item.json.taskDependencies[key] = \"id eq guid'\" + item.json.taskDependencies[key] +\"'\";\n}\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "763b71ac-c78b-4020-9fe1-cc80028edfa7",
      "name": "仅过滤打开的任务",
      "type": "n8n-nodes-base.filter",
      "position": [
        2480,
        -400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8f2bbc21-ad7c-47e2-95b1-f92cb482ea8e",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.taskStatus.type }}",
              "rightValue": "done"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "7d90188e-859e-450f-922a-e74c9f69646d",
      "name": "聚合打开的任务 ID",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        2700,
        -400
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "id"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1aca54ca-3369-456e-942d-ab929879c2a4",
      "name": "便利贴5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1560,
        -500
      ],
      "parameters": {
        "color": 4,
        "width": 1320,
        "height": 340,
        "content": "### 加载任务依赖项并过滤打开的任务"
      },
      "typeVersion": 1
    },
    {
      "id": "d1475f48-a06a-4b67-8374-b1f4c6713eb8",
      "name": "便签 6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2980,
        -500
      ],
      "parameters": {
        "color": 3,
        "width": 420,
        "height": 340,
        "content": "### 检查标记为依赖项的任务是否打开"
      },
      "typeVersion": 1
    },
    {
      "id": "86436ab7-7a4d-47c9-ab9f-9d414205baf3",
      "name": "检查是否存在打开的任务",
      "type": "n8n-nodes-base.if",
      "position": [
        3140,
        -400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c30d2bf0-f6ca-46a6-be1e-2f24425fffed",
              "operator": {
                "type": "array",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3c8971c0-9ad5-4265-add8-9dde8baef83a",
      "name": "便签 7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3500,
        -500
      ],
      "parameters": {
        "color": 4,
        "width": 360,
        "height": 340,
        "content": "### 回滚任务状态"
      },
      "typeVersion": 1
    },
    {
      "id": "f5062a59-4067-49f5-9a3a-3087b09a9629",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3960,
        -500
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "height": 340,
        "content": "### 检查是否应向任务添加注释"
      },
      "typeVersion": 1
    },
    {
      "id": "6b84e668-7dd8-4ff5-ae98-c2dc6a435c07",
      "name": "检查是否启用了注释",
      "type": "n8n-nodes-base.if",
      "position": [
        4120,
        -400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "6505de62-2d0a-4a3a-8f33-f0add4364b7e",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Workflow config').item.json.addComments }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "81f39f77-eacb-4882-9a75-5e01dce04e5c",
      "name": "便签 9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4460,
        -500
      ],
      "parameters": {
        "color": 4,
        "width": 460,
        "height": 340,
        "content": "### 向任务添加关于任务状态回滚的注释"
      },
      "typeVersion": 1
    },
    {
      "id": "cad1126c-4a60-47e2-8b75-0c2b35464497",
      "name": "向任务添加注释",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4640,
        -400
      ],
      "parameters": {
        "url": "=https://api.awork.com/api/v1/tasks/{{ $('Webhook call by Awork').item.json.body.entity.id }}/comments",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"message\": {{ JSON.stringify($('Workflow config').item.json.commentTextDependencies) }}\n} ",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "CmNSbB7CCq63XJLe",
          "name": "Zammad API - TICKET"
        },
        "httpHeaderAuth": {
          "id": "9d0FyCu0IlwrdNkM",
          "name": "Awork Api"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "waitBetweenTries": 2000
    },
    {
      "id": "a98ba8ae-05d4-4175-beed-fd9f40c772d3",
      "name": "检查是否启用了树结构",
      "type": "n8n-nodes-base.if",
      "position": [
        3600,
        120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "53d5f2be-2830-4977-a69f-a0d135ea76c4",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Workflow config').item.json.useTreeStructure }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3464568d-3863-4063-8097-526b60260818",
      "name": "便签11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3500,
        20
      ],
      "parameters": {
        "color": 3,
        "width": 360,
        "height": 340,
        "content": "### 检查是否启用了树结构检查"
      },
      "typeVersion": 1
    },
    {
      "id": "1e2f8502-fc35-4e6f-bb9a-83acb04d57af",
      "name": "便签12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3960,
        20
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "height": 340,
        "content": "### 检查任务是否有子任务"
      },
      "typeVersion": 1
    },
    {
      "id": "d25eeac9-c485-4624-8b9f-b7068a4eb0b5",
      "name": "检查子任务",
      "type": "n8n-nodes-base.if",
      "position": [
        4080,
        100
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "965e2460-236b-4628-b6e9-e4082b656b0f",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $('Webhook call by Awork').item.json.body.entity.numberOfSubtasks }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6bcac41a-3f06-4a35-9703-fdfba98d1ac4",
      "name": "将任务状态从已完成回滚到先前状态",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3620,
        -400
      ],
      "parameters": {
        "url": "https://api.awork.com/api/v1/tasks/changestatuses",
        "method": "POST",
        "options": {},
        "jsonBody": "=[\n  {\n    \"taskId\": \"{{ $('Webhook call by Awork').item.json.body.entity.id }}\",\n    \"statusId\": \"{{ $('Filter task status change').item.json.old }}\" \n}\n] ",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "9d0FyCu0IlwrdNkM",
          "name": "Awork Api"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "waitBetweenTries": 2000
    },
    {
      "id": "38782806-11a3-4976-8ba6-17da89d7a859",
      "name": "加载所有打开的子任务",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4560,
        100
      ],
      "parameters": {
        "url": "=https://api.awork.com/api/v1/me/projecttasks",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "filterby",
              "value": "=parentid eq guid'{{ $('Webhook call by Awork').item.json.body.entity.id }}' and taskstatus/type ne 'done'"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "9d0FyCu0IlwrdNkM",
          "name": "Awork Api"
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": true
    },
    {
      "id": "ad23f9c2-bdb4-48b7-ad6b-776424c0275d",
      "name": "聚合任务 ID",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        4780,
        100
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "id"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "711fd327-892a-48e2-95ea-24a21cba1765",
      "name": "便签10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4460,
        20
      ],
      "parameters": {
        "color": 4,
        "width": 500,
        "height": 340,
        "content": "### 加载未标记为完成的子任务"
      },
      "typeVersion": 1
    },
    {
      "id": "fe844b55-800d-426c-9842-ccb8cc0d33f3",
      "name": "便签14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5060,
        20
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "height": 340,
        "content": "### 检查是否存在打开的子任务"
      },
      "typeVersion": 1
    },
    {
      "id": "946243b8-ceaa-4ce3-a4d1-97bc3ee9f9ed",
      "name": "检查打开的子任务",
      "type": "n8n-nodes-base.if",
      "position": [
        5180,
        100
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f1c49c95-5272-4414-99f6-55e146a33ae2",
              "operator": {
                "type": "array",
                "operation": "lengthGt",
                "rightType": "number"
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e4e43d31-a7c1-404c-a67a-21236314f46c",
      "name": "便签15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5580,
        20
      ],
      "parameters": {
        "color": 4,
        "width": 360,
        "height": 340,
        "content": "### 回滚任务状态"
      },
      "typeVersion": 1
    },
    {
      "id": "7065d3b2-f120-4636-b30e-d919d4ca47c8",
      "name": "便签16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6040,
        20
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "height": 340,
        "content": "### 检查是否应向任务添加注释"
      },
      "typeVersion": 1
    },
    {
      "id": "e4b9348e-de14-425a-b9ed-64891681c49a",
      "name": "检查是否启用了注释1",
      "type": "n8n-nodes-base.if",
      "position": [
        6200,
        120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "6505de62-2d0a-4a3a-8f33-f0add4364b7e",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Workflow config').item.json.addComments }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e01f0f8a-d844-4f51-8c38-044d1be4c3b3",
      "name": "便签17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6540,
        20
      ],
      "parameters": {
        "color": 4,
        "width": 460,
        "height": 340,
        "content": "### 向任务添加关于任务状态回滚的注释"
      },
      "typeVersion": 1
    },
    {
      "id": "65c7656e-f03e-4082-8226-34a052fbdc38",
      "name": "向任务添加注释1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        6720,
        120
      ],
      "parameters": {
        "url": "=https://api.awork.com/api/v1/tasks/{{ $('Webhook call by Awork').item.json.body.entity.id }}/comments",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"message\": {{ JSON.stringify($('Workflow config').item.json.commentTextTreeStructure) }}\n} ",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "CmNSbB7CCq63XJLe",
          "name": "Zammad API - TICKET"
        },
        "httpHeaderAuth": {
          "id": "9d0FyCu0IlwrdNkM",
          "name": "Awork Api"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "waitBetweenTries": 2000
    },
    {
      "id": "0521eaf8-0719-4691-be1d-82a6defa87ca",
      "name": "将任务状态从已完成回滚到先前状态1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        5700,
        120
      ],
      "parameters": {
        "url": "https://api.awork.com/api/v1/tasks/changestatuses",
        "method": "POST",
        "options": {},
        "jsonBody": "=[\n  {\n    \"taskId\": \"{{ $('Webhook call by Awork').item.json.body.entity.id }}\",\n    \"statusId\": \"{{ $('Filter task status change').item.json.old }}\" \n}\n] ",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "9d0FyCu0IlwrdNkM",
          "name": "Awork Api"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "waitBetweenTries": 2000
    },
    {
      "id": "0a266961-2e39-4508-a37e-9a5ec6811466",
      "name": "便签13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -740,
        -660
      ],
      "parameters": {
        "color": 4,
        "width": 280,
        "content": "## 绿色便签:节点的逻辑分组"
      },
      "typeVersion": 1
    },
    {
      "id": "a2014e67-29c9-49fb-86eb-0e5fe0969455",
      "name": "便签18",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        -660
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "content": "## 红色便签:路由和可能的工作流退出"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Check subtasks": {
      "main": [
        [
          {
            "node": "Load all open sub tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow config": {
      "main": [
        [
          {
            "node": "Fetch task changes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate task IDs": {
      "main": [
        [
          {
            "node": "Check open subtasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if task done": {
      "main": [
        [
          {
            "node": "Check if dependencies enabled",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch task changes": {
      "main": [
        [
          {
            "node": "Split out task changes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build filter params": {
      "main": [
        [
          {
            "node": "Load all linked tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check open subtasks": {
      "main": [
        [
          {
            "node": "Roll back task status from done to previous state1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add comment to tasks": {
      "main": [
        []
      ]
    },
    "Load all linked tasks": {
      "main": [
        [
          {
            "node": "Filter only open tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook call by Awork": {
      "main": [
        [
          {
            "node": "Workflow config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter only open tasks": {
      "main": [
        [
          {
            "node": "Aggregate open task IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split out task changes": {
      "main": [
        [
          {
            "node": "Filter task status change",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate open task IDs": {
      "main": [
        [
          {
            "node": "Check if open tasks exist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load all open sub tasks": {
      "main": [
        [
          {
            "node": "Aggregate task IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if open tasks exist": {
      "main": [
        [
          {
            "node": "Roll back task status from done to previous state",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check if tree structure enabled",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter task status change": {
      "main": [
        [
          {
            "node": "Check if task done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load dependencies for task": {
      "main": [
        [
          {
            "node": "Aggregate task dependencies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate task dependencies": {
      "main": [
        [
          {
            "node": "Build filter params",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if comments are enabled": {
      "main": [
        [
          {
            "node": "Add comment to tasks",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Check if dependencies enabled": {
      "main": [
        [
          {
            "node": "Load dependencies for task",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check if tree structure enabled",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if comments are enabled1": {
      "main": [
        [
          {
            "node": "Add comment to tasks1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if tree structure enabled": {
      "main": [
        [
          {
            "node": "Check subtasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Roll back task status from done to previous state": {
      "main": [
        [
          {
            "node": "Check if comments are enabled",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Roll back task status from done to previous state1": {
      "main": [
        [
          {
            "node": "Check if comments are enabled1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - IT 运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量44
分类1
节点类型9
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流