8
n8n 中文网amn8n.com

基于蓝图和Baserow的自动化任务生成与周末感知调度

中级

这是一个Project Management领域的自动化工作流,包含 12 个节点。主要使用 Set, Code, Baserow, Webhook, Aggregate 等节点。 基于蓝图和Baserow的自动化任务生成与周末感知调度

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "nodes": [
    {
      "id": "0a933c3b-9f6b-4f45-97ec-e3cc4d343a97",
      "name": "批量生成任务",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        1312,
        544
      ],
      "parameters": {
        "url": "={{ $('Configure settings and ids').item.json['API host'] }}/api/database/rows/table/{{ $('Configure settings and ids').item.json['Tasks table ID'] }}/batch/?user_field_names=true",
        "method": "POST",
        "options": {},
        "jsonBody": "={\"items\": {{ JSON.stringify($json.items) }}}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Token {{ $('Configure settings and ids').item.json.Token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "95e2115f-702f-42dc-8320-605727f05017",
      "name": "聚合任务以插入",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1088,
        544
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "items"
      },
      "typeVersion": 1
    },
    {
      "id": "ada410ae-504e-418b-9a5c-cdeec042e68c",
      "name": "错误响应",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1536,
        640
      ],
      "parameters": {
        "options": {},
        "respondWith": "text",
        "responseBody": "❌ Something went wrong, please check the log files"
      },
      "typeVersion": 1.4
    },
    {
      "id": "d980e86e-b261-4ddf-b73d-45dd3b9fbf56",
      "name": "获取所有模板步骤",
      "type": "n8n-nodes-base.baserow",
      "position": [
        416,
        544
      ],
      "parameters": {
        "tableId": "={{ $json[\"Detail template table ID\"] }}",
        "returnAll": true,
        "databaseId": "={{ $json[\"Database ID\"] }}",
        "additionalOptions": {
          "filters": {
            "fields": [
              {
                "field": "={{ $json[\"Link to master template field ID\"] }}",
                "value": "={{ $('Trigger task creation').item.json.body.template_id }}",
                "operator": "link_row_has"
              }
            ]
          }
        }
      },
      "credentials": {
        "baserowApi": {
          "id": "HgVHAoZFovwlleMD",
          "name": "Baserow SaaS account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "12f6eb7e-1dd5-4d67-995f-493d58197d46",
      "name": "触发任务创建",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -32,
        544
      ],
      "webhookId": "5d4788bb-3dae-4f4d-9f4f-31fc23721840",
      "parameters": {
        "path": "create-tasks-for-template",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "e188e6da-2de1-4dfb-a203-0319ff720a80",
      "name": "避免在周末安排",
      "type": "n8n-nodes-base.code",
      "position": [
        864,
        544
      ],
      "parameters": {
        "jsCode": "function adjustDateForWeekend(original_date){\n  const new_date = new Date(original_date)\n  const day = new_date.getDay();\n  // check for Saturday: add 2 days if necessary\n  if(day == 6){\n    new_date.setDate(new_date.getDate() + 2)\n  }\n  // check for Sunday: add 1 day if necessary\n  if(day == 0){\n    new_date.setDate(new_date.getDate() + 1)\n  }\n  //return the new day in format YYYY-mm-dd\n  return new_date.toISOString().slice(0,10)\n}\n\n// Loop over all the deadlines and adjust to the next monday if the original date is during the weekend\nfor (const item of $input.all()) {\n  item.json.Deadline = adjustDateForWeekend(item.json.Deadline);\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "907e6348-ec6f-434b-b7b2-4568d2a27e7d",
      "name": "计算每个步骤的截止日期",
      "type": "n8n-nodes-base.set",
      "position": [
        640,
        544
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fbdee67a-9eb1-4970-9f51-103002e69253",
              "name": "Procedure step",
              "type": "array",
              "value": "=[{{ $json.id }}]"
            },
            {
              "id": "abd084cc-b13f-48d2-a0ff-31398bce757a",
              "name": "Deadline",
              "type": "string",
              "value": "={{new Date($('Configure settings and ids').item.json['Schedule date']).plus($json['Days to complete'],'days').format('yyyy-MM-dd')}}"
            },
            {
              "id": "cf93c092-6126-4b36-a9ce-3725e1a7e47b",
              "name": "Assignee",
              "type": "array",
              "value": "=[{{ $('Configure settings and ids').item.json['Assignee ID'] }}]"
            },
            {
              "id": "6127e270-7305-4a61-b22a-8273544487b3",
              "name": "Note",
              "type": "string",
              "value": "={{ $('Configure settings and ids').item.json.Note }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2514909f-2cba-41b2-9a7f-0a7c4b41a61a",
      "name": "配置设置和 ID",
      "type": "n8n-nodes-base.set",
      "position": [
        192,
        544
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "644a34f8-a7dc-4812-a5b6-4efa5b47efa1",
              "name": "API host",
              "type": "string",
              "value": "https://api.baserow.io"
            },
            {
              "id": "daba6cf7-c391-4a08-89c7-6164ce5b594e",
              "name": "Token",
              "type": "string",
              "value": "<your_token>"
            },
            {
              "id": "ba45eee9-7823-4e83-bbc0-e1754c04709d",
              "name": "Database ID",
              "type": "number",
              "value": 1111
            },
            {
              "id": "c8a493c3-2ff4-4f63-9a99-b586c14cf4a1",
              "name": "Detail template table ID",
              "type": "number",
              "value": 1111
            },
            {
              "id": "9a4c326a-1581-47bf-b5da-35084656e5f3",
              "name": "Link to master template field ID",
              "type": "string",
              "value": "1111"
            },
            {
              "id": "a420b11a-e75f-45ef-b4ab-373d5754edc2",
              "name": "Tasks table ID",
              "type": "number",
              "value": 1111
            },
            {
              "id": "507da617-8380-437e-ad09-2355e1473544",
              "name": "Assignee ID",
              "type": "number",
              "value": "={{ $json.body.assignee_id }}"
            },
            {
              "id": "59cb1495-86e3-4795-b05b-65e61c9907fb",
              "name": "Schedule date",
              "type": "string",
              "value": "={{ $if(typeof $json.body.schedule_date == 'undefined',$now.format('yyyy-MM-dd'), $json.body.schedule_date)}}"
            },
            {
              "id": "2bf36248-a5a9-49b2-bf5f-8387034159bb",
              "name": "Note",
              "type": "string",
              "value": "={{ $json.body.note }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8f2b7922-2f35-427e-8b65-5c1220122000",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1088,
        -112
      ],
      "parameters": {
        "width": 928,
        "height": 1920,
        "content": "此 n8n 模板演示了如何基于模板或蓝图表在 Baserow 中自动**创建** **任务**(或一般记录)。第一个蓝图表是**主表**,保存模板的常规信息。例如:处理事件的标准程序。第二个表是**详情表**,保存模板的多个记录。该表中的每个记录都是需要分配给某人并设定特定截止日期的具体任务。"
      },
      "typeVersion": 1
    },
    {
      "id": "df72abe3-8919-4854-ace5-0a35ed2a25c9",
      "name": "成功响应",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1536,
        448
      ],
      "parameters": {
        "options": {},
        "respondWith": "text",
        "responseBody": "✅ The tasks were created"
      },
      "typeVersion": 1.4
    },
    {
      "id": "3ec01ca3-cbb1-4932-8a26-63609021fb43",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        736
      ],
      "parameters": {
        "color": 7,
        "width": 688,
        "height": 944,
        "content": "## 触发任务创建"
      },
      "typeVersion": 1
    },
    {
      "id": "4e516ff5-099a-4c9f-a881-846b6d1d25b6",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        144,
        160
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 352,
        "content": "## 配置设置和 ID"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Trigger task creation": {
      "main": [
        [
          {
            "node": "Configure settings and ids",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get all template steps": {
      "main": [
        [
          {
            "node": "Calculate deadlines for each step",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate tasks in batch": {
      "main": [
        [
          {
            "node": "Success response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate tasks for insert": {
      "main": [
        [
          {
            "node": "Generate tasks in batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure settings and ids": {
      "main": [
        [
          {
            "node": "Get all template steps",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate deadlines for each step": {
      "main": [
        [
          {
            "node": "Avoid scheduling during the weekend",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Avoid scheduling during the weekend": {
      "main": [
        [
          {
            "node": "Aggregate tasks for insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 项目管理

需要付费吗?

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

工作流信息
难度等级
中级
节点数量12
分类1
节点类型8
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Frederik Duchi

Frederik Duchi

@frederikdc

I have a background in software engineering and work as a product specialist at Baserow and already did a lot of implementations for customers where I combine Baserow with n8n.

外部链接
在 n8n.io 查看

分享此工作流