自动化Awork任务时间跟踪执行与清理
高级
这是一个IT Ops领域的自动化工作流,包含 58 个节点。主要使用 If, Set, Code, Filter, Switch 等节点。 自动化Awork任务时间跟踪执行与清理
前置要求
- •HTTP Webhook 端点(n8n 会自动生成)
- •可能需要目标 API 的认证凭证
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "93fb8727a95622f4aa18b433e7f50b3d9eefa47fbe8901532956ded5db485301"
},
"nodes": [
{
"id": "179c1408-eeb6-48e3-a345-4b9b1869858b",
"name": "工作流配置",
"type": "n8n-nodes-base.set",
"position": [
-780,
700
],
"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": "forceTimeTracking",
"type": "boolean",
"value": true
},
{
"id": "ffd4703d-be65-4c35-b28c-6cafb1050d13",
"name": "limitForceTimeTrackingToTags",
"type": "array",
"value": "[\"Orga\"]"
},
{
"id": "6adacba5-463e-4d5e-9571-54f1a026cb4d",
"name": "addComments",
"type": "boolean",
"value": true
},
{
"id": "a06d3f03-8c2d-4788-b986-4bfc2b2a37c5",
"name": "commentTimeNotTracked",
"type": "string",
"value": "Time not tracked! Status rolled back!"
},
{
"id": "6523a631-b41c-4c52-824a-09f0997b099a",
"name": "setMinTimeTracking",
"type": "number",
"value": 15
},
{
"id": "966f97fd-34f5-4886-a36a-20d930ab1877",
"name": "minTimeTrackingTags",
"type": "array",
"value": "[\"Abrechnen\"]"
},
{
"id": "9d1979f2-cb8e-4ef8-ac1a-8d2a40e394d2",
"name": "cleanupTimeTracking",
"type": "boolean",
"value": true
},
{
"id": "cf342344-7520-450e-ac04-16ca15db1c69",
"name": "cleanupTimeTrackingInterval",
"type": "number",
"value": 15
},
{
"id": "9d75cff6-5b2f-4ee8-b165-e623aa85a0cb",
"name": "cleanupTimeTrackingTolerance",
"type": "number",
"value": 1
},
{
"id": "2ccaff8c-9c16-45a7-ba79-8a676f2ca047",
"name": "billingTag",
"type": "array",
"value": "[\"Abrechnen\"]"
},
{
"id": "f2081a66-3de8-41e2-b399-edb5a3e133c9",
"name": "forceStartTime",
"type": "boolean",
"value": true
},
{
"id": "88cd0d2a-090b-4518-bcec-556aa51fda1a",
"name": "forceStartTimeText",
"type": "string",
"value": "System generated start time"
},
{
"id": "0d88bd24-1306-4986-88c7-8d4b2ffc9d02",
"name": "systemWorkType",
"type": "string",
"value": "System time tracking"
},
{
"id": "ce3be14c-8736-42b5-b5fa-5ff03da56173",
"name": "systemWorkText",
"type": "string",
"value": "System generated time tracking"
},
{
"id": "0886dafd-51e4-4bb8-8b9e-bf3818bc82e2",
"name": "timeZone",
"type": "string",
"value": "Europe/Berlin"
},
{
"id": "683813c2-8a3f-4308-bad4-df694b452b36",
"name": "systemTimeUserId",
"type": "string",
"value": ""
}
]
}
},
"typeVersion": 3.4
},
{
"id": "3e7a91e0-b098-4b1e-b4f8-34e83457c5e1",
"name": "获取任务变更",
"type": "n8n-nodes-base.set",
"position": [
-360,
700
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "d1e893cd-bdeb-4c9b-8fe0-82dc11c047a7",
"name": "=changes",
"type": "array",
"value": "={{ $('Webhook call by Awork').item.json.body.changes }}"
},
{
"id": "366f0193-6a2d-4766-9d70-1f75659192a0",
"name": "eventType",
"type": "string",
"value": "={{ $('Webhook call by Awork').item.json.body.eventType }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "511f086c-d49f-4ed6-8bf5-73ac32546323",
"name": "拆分任务变更",
"type": "n8n-nodes-base.splitOut",
"position": [
-140,
700
],
"parameters": {
"options": {},
"fieldToSplitOut": "changes"
},
"typeVersion": 1
},
{
"id": "9b5e7bc8-2c9d-4477-bf9a-89016a289e7b",
"name": "过滤任务状态变更",
"type": "n8n-nodes-base.filter",
"position": [
80,
700
],
"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,
"alwaysOutputData": true
},
{
"id": "0709319c-03ed-49f7-b9ef-479cf2a2d7e0",
"name": "检查任务是否完成",
"type": "n8n-nodes-base.if",
"position": [
940,
60
],
"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": "f516a0c5-098b-49c4-8d7c-efd024da4a0c",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2080,
40
],
"parameters": {
"width": 880,
"height": 1900,
"content": "## awork的增强时间跟踪功能"
},
"typeVersion": 1
},
{
"id": "215d70e6-5ae9-4342-9b15-54459e96252f",
"name": "Awork的Webhook调用",
"type": "n8n-nodes-base.webhook",
"position": [
-1080,
700
],
"webhookId": "d6af5915-8ba8-46ec-a840-6fe9d0a66cc6",
"parameters": {
"path": "d6af5915-8ba8-46ec-a840-6fe9d0a66cc6",
"options": {},
"httpMethod": "POST"
},
"typeVersion": 2
},
{
"id": "0674b425-48b5-44c1-8a4c-18446eed49ee",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-880,
600
],
"parameters": {
"color": 4,
"width": 360,
"height": 280,
"content": "### 工作流配置"
},
"typeVersion": 1
},
{
"id": "9b085c61-09af-4ee4-8e0b-17c97e46d17b",
"name": "便签 2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-400,
600
],
"parameters": {
"color": 4,
"width": 660,
"height": 280,
"content": "### 从webhook调用有效负载中提取状态更改"
},
"typeVersion": 1
},
{
"id": "136ad4d1-aaab-4c5e-87aa-2ebbb90f015c",
"name": "便签 3",
"type": "n8n-nodes-base.stickyNote",
"position": [
820,
-40
],
"parameters": {
"color": 3,
"width": 340,
"height": 280,
"content": "### 检查任务状态当前是否为\"完成\""
},
"typeVersion": 1
},
{
"id": "9d5c4669-a5ee-4824-94aa-df6b2cc56809",
"name": "便签 4",
"type": "n8n-nodes-base.stickyNote",
"position": [
1280,
-40
],
"parameters": {
"color": 3,
"width": 380,
"height": 280,
"content": "### 检查是否启用了强制时间跟踪且没有跟踪时间"
},
"typeVersion": 1
},
{
"id": "9d0261e8-4aa2-4517-aa21-8a1a8d669e4b",
"name": "便签22",
"type": "n8n-nodes-base.stickyNote",
"position": [
-980,
40
],
"parameters": {
"color": 4,
"width": 280,
"content": "## 绿色便签:节点的逻辑组"
},
"typeVersion": 1
},
{
"id": "390668f3-be8e-435b-b587-b8051602cb24",
"name": "便签23",
"type": "n8n-nodes-base.stickyNote",
"position": [
-620,
40
],
"parameters": {
"color": 3,
"width": 280,
"content": "## 红色便签:路由和可能的工作流退出"
},
"typeVersion": 1
},
{
"id": "06b9eb83-b591-4533-b25a-6c3137dedd27",
"name": "检查是否启用了强制时间跟踪",
"type": "n8n-nodes-base.if",
"position": [
1420,
60
],
"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.forceTimeTracking }}",
"rightValue": "true"
},
{
"id": "a26d4003-614b-416a-9e99-93401ca4df95",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $('Webhook call by Awork').item.json.body.entity.totalTrackedDuration }}",
"rightValue": 0
}
]
}
},
"typeVersion": 2.2
},
{
"id": "4ca7bf23-1aae-4f02-be65-c73b95d7267a",
"name": "便签 5",
"type": "n8n-nodes-base.stickyNote",
"position": [
1780,
-40
],
"parameters": {
"color": 3,
"width": 360,
"height": 280,
"content": "### 检查强制时间跟踪是否限制到特定标签"
},
"typeVersion": 1
},
{
"id": "b5ef7954-3afa-476c-94da-a20e86a2307f",
"name": "处理标签并检查是否在配置的标签中找到",
"type": "n8n-nodes-base.code",
"position": [
2560,
-400
],
"parameters": {
"jsCode": "let tagFound = false;\n\nfor (const item of $('Webhook call by Awork').first().json.body.entity.tags) {\n if($('Workflow config').first().json.limitForceTimeTrackingToTags.includes(item.name)){\n tagFound = true;\n }\n}\nreturn {\n \"json\" : {\n \"tagFound\": tagFound\n }\n}"
},
"typeVersion": 2
},
{
"id": "9495c5fa-a1f0-4ee6-8aee-8d50b34e3f62",
"name": "便签18",
"type": "n8n-nodes-base.stickyNote",
"position": [
2440,
-520
],
"parameters": {
"color": 4,
"width": 360,
"height": 340,
"content": "### 处理任务标签"
},
"typeVersion": 1
},
{
"id": "476d35a9-2d22-42c6-8da6-e6c19b551ce6",
"name": "便签19",
"type": "n8n-nodes-base.stickyNote",
"position": [
2920,
-520
],
"parameters": {
"color": 3,
"width": 400,
"height": 340,
"content": "### 检查是否至少有一个任务标签列在配置节点中"
},
"typeVersion": 1
},
{
"id": "73b880a2-a517-409a-81b4-0b8864077ce6",
"name": "检查标签是否列在配置节点中",
"type": "n8n-nodes-base.if",
"position": [
3060,
-400
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "8ff048ba-25bd-4bd5-b0da-f4a53e056582",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.tagFound }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "f3abc505-6c3c-4651-9442-0888c90a6b94",
"name": "便签20",
"type": "n8n-nodes-base.stickyNote",
"position": [
3440,
-520
],
"parameters": {
"color": 4,
"width": 360,
"height": 340,
"content": "### 回滚任务状态"
},
"typeVersion": 1
},
{
"id": "65aaba6d-e2ce-4563-ad98-80f960588d10",
"name": "便签21",
"type": "n8n-nodes-base.stickyNote",
"position": [
3900,
-520
],
"parameters": {
"color": 3,
"width": 400,
"height": 340,
"content": "### 检查是否应向任务添加评论"
},
"typeVersion": 1
},
{
"id": "90e2355d-f1ab-4b8a-badc-759f5ce92bec",
"name": "检查是否启用了评论",
"type": "n8n-nodes-base.if",
"position": [
4060,
-420
],
"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": "16c319d2-c0bb-4746-9716-e8979415144f",
"name": "便签24",
"type": "n8n-nodes-base.stickyNote",
"position": [
4400,
-520
],
"parameters": {
"color": 4,
"width": 460,
"height": 340,
"content": "### 添加关于任务状态回滚的评论到任务"
},
"typeVersion": 1
},
{
"id": "d585a9ae-453a-4ac3-ae01-974683ae8db6",
"name": "向任务添加评论",
"type": "n8n-nodes-base.httpRequest",
"position": [
4580,
-420
],
"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.commentTimeNotTracked) }}\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": "ca27d942-452c-4d74-95c1-062e8efa3878",
"name": "将任务状态从完成回滚到先前状态",
"type": "n8n-nodes-base.httpRequest",
"position": [
3560,
-420
],
"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": "546c19a9-d666-43ca-b796-c4051aea1e79",
"name": "检查标签限制",
"type": "n8n-nodes-base.if",
"position": [
1880,
80
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "727bf023-2759-44e0-aa51-fcf4fdf3b2c2",
"operator": {
"type": "array",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $('Workflow config').item.json.limitForceTimeTrackingToTags }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "f40cd133-4cb2-4c3c-857e-52dfbe5f41ee",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
3060,
1240
],
"parameters": {
"color": 3,
"width": 360,
"height": 280,
"content": "### 检查是否启用了最小时间跟踪或时间跟踪清理"
},
"typeVersion": 1
},
{
"id": "abd49a4a-4837-4070-9fe9-1de7a47aa15f",
"name": "便签7",
"type": "n8n-nodes-base.stickyNote",
"position": [
5080,
1240
],
"parameters": {
"color": 3,
"width": 380,
"height": 280,
"content": "### 检查跟踪时间是否小于最小时间"
},
"typeVersion": 1
},
{
"id": "75a23ae3-4970-48da-8a18-192f7f7d6708",
"name": "检查跟踪时间",
"type": "n8n-nodes-base.if",
"position": [
5220,
1380
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "b68cd162-9937-44d6-8e37-73744f79ccb1",
"operator": {
"type": "number",
"operation": "lt"
},
"leftValue": "={{ $('Webhook call by Awork').item.json.body.changes.find(entry => entry.property === \"Duration\")['new'].toNumber() }}",
"rightValue": "={{ ($('Workflow config').item.json.setMinTimeTracking * 60) }}"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "a1c8d19e-34a4-4eed-8ab7-b1bc72758f66",
"name": "便签15",
"type": "n8n-nodes-base.stickyNote",
"position": [
2440,
160
],
"parameters": {
"color": 4,
"width": 360,
"height": 320,
"content": "### 回滚任务状态"
},
"typeVersion": 1
},
{
"id": "c04685af-e198-4272-93d3-b0bbd7f3a94a",
"name": "便签16",
"type": "n8n-nodes-base.stickyNote",
"position": [
2900,
160
],
"parameters": {
"color": 3,
"width": 400,
"height": 320,
"content": "### 检查是否应向任务添加评论"
},
"typeVersion": 1
},
{
"id": "e7c2f529-ee42-4417-a92e-b1c0b255fccf",
"name": "检查是否启用了评论1",
"type": "n8n-nodes-base.if",
"position": [
3060,
260
],
"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": "21de0e65-7bb2-48a4-90f5-836758322b03",
"name": "便签17",
"type": "n8n-nodes-base.stickyNote",
"position": [
3400,
160
],
"parameters": {
"color": 4,
"width": 460,
"height": 320,
"content": "### 添加关于任务状态回滚的评论到任务"
},
"typeVersion": 1
},
{
"id": "12e1a026-3b5a-4cd3-94ea-8892145ec9ec",
"name": "向任务添加评论1",
"type": "n8n-nodes-base.httpRequest",
"position": [
3580,
260
],
"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.commentTimeNotTracked) }}\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": "8d83c66e-1e1a-47d7-ada6-894816906875",
"name": "将任务状态从完成回滚到先前状态1",
"type": "n8n-nodes-base.httpRequest",
"position": [
2560,
260
],
"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": "07ded81a-712f-49a9-8e76-8eb716cc99d7",
"name": "计算要添加的时间跟踪的时间",
"type": "n8n-nodes-base.code",
"position": [
5720,
1160
],
"parameters": {
"jsCode": "let trackedTime = $('Webhook call by Awork').first().json.body.changes.find(entry => entry.property === \"Duration\")[\"new\"];\n\n\nlet requiredTime = $('Workflow config').first().json.setMinTimeTracking * 60;\n\nlet missingTrackedTime = requiredTime - trackedTime;\n\n\nlet result = {};\n\nlet isBillable = false;\n\nfor (const item of $('Load task details for time tracking item').first().json.tags) {\n if($('Workflow config').first().json.billingTag.includes(item.name)){\n isBillable = true;\n }\n}\n\nif(missingTrackedTime > 0){\n\n result = {\n \"json\" : {\n \"addTimeTracking\" : true,\n \"missingTrackedTime\": missingTrackedTime,\n \"isBillable\" : isBillable\n }\n };\n \n}else{\n result = {\n \"json\" : {\n \"addTimeTracking\" : false,\n \"missingTrackedTime\": 0,\n \"isBillable\" : isBillable\n }\n };\n}\n\nreturn result;"
},
"typeVersion": 2
},
{
"id": "a5332052-88fb-4eea-9e9f-4ac5ad1920b3",
"name": "计算要添加的时间跟踪的时间1",
"type": "n8n-nodes-base.code",
"position": [
5680,
1620
],
"parameters": {
"jsCode": "let trackedTime = $('Webhook call by Awork').first().json.body.changes.find(entry => entry.property === \"Duration\")[\"new\"];\n\nlet requiredTimeInterval = $('Workflow config').first().json.cleanupTimeTrackingInterval * 60;\n\nlet moduloTrackedTime = trackedTime % requiredTimeInterval;\n\nlet trackedTimeTolerance = $('Workflow config').first().json.cleanupTimeTrackingTolerance * 60;\n\nlet missingTrackedTime = 0;\nif(moduloTrackedTime > 0 && moduloTrackedTime > trackedTimeTolerance){\n missingTrackedTime = requiredTimeInterval - moduloTrackedTime;\n}\n\n\nlet result = {};\n\nlet isBillable = false;\n\nfor (const item of $('Load task details for time tracking item').first().json.tags) {\n if($('Workflow config').first().json.billingTag.includes(item.name)){\n isBillable = true;\n }\n}\n\n\nif(missingTrackedTime > 0){\n\n result = {\n \"json\" : {\n \"addTimeTracking\" : true,\n \"missingTrackedTime\": missingTrackedTime,\n \"isBillable\" : isBillable\n }\n };\n \n}else{\n result = {\n \"json\" : {\n \"addTimeTracking\" : false,\n \"missingTrackedTime\": 0,\n \"isBillable\" : isBillable \n }\n };\n}\n\nreturn result;"
},
"typeVersion": 2
},
{
"id": "d4a81a5f-f1a4-4232-a431-707716279840",
"name": "将任务状态从完成回滚到先前状态4",
"type": "n8n-nodes-base.httpRequest",
"position": [
6060,
1620
],
"parameters": {
"url": "https://api.awork.com/api/v1/timeentries",
"method": "POST",
"options": {},
"jsonBody": "={\n \"isBillable\": {{ $('Calculate time for added time tracking1').item.json.isBillable }},\n \"isBilled\": false,\n \"taskId\": \"{{ $('Load task details for time tracking item').item.json.id }}\", \n \"note\": \"{{ $('Workflow config').item.json.systemWorkText }}\", \n \"timezone\": \"{{ $('Workflow config').item.json.timeZone }}\",\n \"duration\": {{ $('Calculate time for added time tracking1').item.json.missingTrackedTime }},\n \"breakDuration\": null, \n \"startDateUtc\": \"{{ $now.setZone('Europe/Berlin').minus($('Calculate time for added time tracking1').item.json.missingTrackedTime,'seconds').startOf('day').toISO() }}\",\n \"startTimeUtc\": \"{{ $now.minus($('Calculate time for added time tracking1').item.json.missingTrackedTime,'seconds').format('HH:mm:ii') }}\",\n \"typeOfWorkId\": \"{{ $('Load system type of work').item.json.id }}\",\n \"userId\": \"{{ $('Workflow config').item.json.systemTimeUserId }}\" \n}",
"sendBody": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "9d0FyCu0IlwrdNkM",
"name": "Awork Api"
}
},
"retryOnFail": true,
"typeVersion": 4.2,
"waitBetweenTries": 2000
},
{
"id": "21b57017-94b3-4fff-b30a-1ec90c1224dc",
"name": "便签8",
"type": "n8n-nodes-base.stickyNote",
"position": [
5600,
1060
],
"parameters": {
"color": 4,
"width": 660,
"height": 280,
"content": "### 计算缺失的跟踪时间并向任务添加系统生成的时间跟踪"
},
"typeVersion": 1
},
{
"id": "252f676f-6d13-401d-b409-ec7dc07c1313",
"name": "### 替换 Airtable 连接",
"type": "n8n-nodes-base.stickyNote",
"position": [
5600,
1540
],
"parameters": {
"color": 4,
"width": 660,
"height": 280,
"content": "### 更新跟踪时间以匹配时间跟踪间隔"
},
"typeVersion": 1
},
{
"id": "622e08a4-6754-4578-9bca-daf2450c061b",
"name": "检查是否启用了最小时间跟踪或时间跟踪清理",
"type": "n8n-nodes-base.if",
"position": [
3140,
1340
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "or",
"conditions": [
{
"id": "b68cd162-9937-44d6-8e37-73744f79ccb1",
"operator": {
"type": "number",
"operation": "gt"
},
"leftValue": "={{ ($('Workflow config').item.json.setMinTimeTracking) }}",
"rightValue": 0
},
{
"id": "8acdd656-81bb-46eb-a776-dbadac4d99f9",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $('Workflow config').item.json.cleanupTimeTracking }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "953b4ce3-ca3d-4e43-b72a-75274215682d",
"name": "便签10",
"type": "n8n-nodes-base.stickyNote",
"position": [
3580,
1240
],
"parameters": {
"color": 3,
"width": 360,
"height": 280,
"content": "### 检查最小时间跟踪是否限制到特定标签"
},
"typeVersion": 1
},
{
"id": "7b334938-3a49-4b63-a215-5b65a576ceb7",
"name": "检查标签限制1",
"type": "n8n-nodes-base.if",
"position": [
3680,
1360
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "727bf023-2759-44e0-aa51-fcf4fdf3b2c2",
"operator": {
"type": "array",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $('Workflow config').item.json.minTimeTrackingTags }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "7b238335-f3b4-417a-8b94-a5f538719205",
"name": "处理标签并检查是否在配置的标签中找到1",
"type": "n8n-nodes-base.code",
"position": [
4220,
1080
],
"parameters": {
"jsCode": "let tagFound = false;\n\nfor (const item of $('Load task details for time tracking item').first().json.tags) {\n if($('Workflow config').first().json.minTimeTrackingTags.includes(item.name)){\n tagFound = true;\n }\n}\nreturn {\n \"json\" : {\n \"tagFound\": tagFound\n }\n}"
},
"typeVersion": 2
},
{
"id": "e9aa2e6b-9ceb-4f09-9bab-4d984b395b89",
"name": "便签25",
"type": "n8n-nodes-base.stickyNote",
"position": [
4080,
980
],
"parameters": {
"color": 4,
"width": 380,
"height": 280,
"content": "### 处理任务标签"
},
"typeVersion": 1
},
{
"id": "ef5df167-732f-4ae4-9e8e-84177b70ff9c",
"name": "如果",
"type": "n8n-nodes-base.if",
"position": [
4720,
1080
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "d6e66e14-c903-45f3-9b16-2ee4916fffc3",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "b9043a45-2643-4160-8997-2a8ce936e0d0",
"name": "Switch",
"type": "n8n-nodes-base.switch",
"position": [
300,
700
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "Task status changed workflow",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "8704542a-861d-4acd-bb37-36162f3d5cba",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Fetch task changes').item.json.eventType }}",
"rightValue": "task_status_changed"
}
]
},
"renameOutput": true
},
{
"outputKey": "Time tracking added workflow",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "1059e3a8-101c-48d6-bb2a-bc98811dbf85",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Fetch task changes').item.json.eventType }}",
"rightValue": "timetracking_added"
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "186b00a1-e27d-466a-a838-5c9f5755546b",
"name": "加载时间跟踪项的任务详细信息",
"type": "n8n-nodes-base.httpRequest",
"position": [
1580,
1320
],
"parameters": {
"url": "=https://api.awork.com/api/v1/tasks/{{ $('Webhook call by Awork').item.json.body.entity.task.id }}",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "9d0FyCu0IlwrdNkM",
"name": "Awork Api"
}
},
"retryOnFail": true,
"typeVersion": 4.2,
"waitBetweenTries": 2000
},
{
"id": "f7516774-cc65-468a-93e5-8ea7b8157d0e",
"name": "便签11",
"type": "n8n-nodes-base.stickyNote",
"position": [
4580,
980
],
"parameters": {
"color": 3,
"width": 380,
"height": 280,
"content": "### 检查任务是否应按标签进行时间跟踪"
},
"typeVersion": 1
},
{
"id": "2262bfbf-3413-4686-892f-9072d688bd66",
"name": "条件判断1",
"type": "n8n-nodes-base.if",
"position": [
860,
1340
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "581dcdf0-5c48-4645-a6f8-df15bfcb7fcd",
"operator": {
"type": "string",
"operation": "notEquals"
},
"leftValue": "={{ $('Webhook call by Awork').item.json.body.entity.typeOfWork.name }}",
"rightValue": "={{ $('Workflow config').item.json.systemWorkType }}"
},
{
"id": "dc0036ee-c92c-4840-a399-8b960ef17753",
"operator": {
"type": "string",
"operation": "notContains"
},
"leftValue": "={{ $('Webhook call by Awork').item.json.body.entity.note }}",
"rightValue": "={{ $('Workflow config').item.json.forceStartTimeText }}"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "891c6828-17a9-4c99-b616-9fbe9fc8b5e9",
"name": "加载系统工作类型",
"type": "n8n-nodes-base.httpRequest",
"position": [
1320,
1320
],
"parameters": {
"url": "=https://api.awork.com/api/v1/typeofwork?filterby=name eq '{{ $('Workflow config').item.json.systemWorkType }}' ",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "9d0FyCu0IlwrdNkM",
"name": "Awork Api"
}
},
"retryOnFail": true,
"typeVersion": 4.2,
"waitBetweenTries": 2000
},
{
"id": "91b17bed-b86f-4345-9ec8-76b943e989ae",
"name": "便签12",
"type": "n8n-nodes-base.stickyNote",
"position": [
740,
1240
],
"parameters": {
"color": 3,
"width": 360,
"height": 280,
"content": "### 检查添加的时间跟踪是否不是系统生成的,以防止无限循环"
},
"typeVersion": 1
},
{
"id": "d866932b-0e94-4a8c-acc6-62c470ac316e",
"name": "便签26",
"type": "n8n-nodes-base.stickyNote",
"position": [
1240,
1240
],
"parameters": {
"color": 4,
"width": 560,
"height": 280,
"content": "### 加载系统工作类型和相关任务数据"
},
"typeVersion": 1
},
{
"id": "56edd5c1-f352-457a-9d81-1a5af8db3d9e",
"name": "添加跟踪时间以匹配最小时间设置",
"type": "n8n-nodes-base.httpRequest",
"position": [
6040,
1160
],
"parameters": {
"url": "https://api.awork.com/api/v1/timeentries",
"method": "POST",
"options": {},
"jsonBody": "={\n \"isBillable\": {{ $('Calculate time for added time tracking').item.json.isBillable }},\n \"isBilled\": false,\n \"taskId\": \"{{ $('Load task details for time tracking item').item.json.id }}\", \n \"note\": \"{{ $('Workflow config').item.json.systemWorkText }}\", \n \"timezone\": \"{{ $('Workflow config').item.json.timeZone }}\",\n \"duration\": {{ $('Calculate time for added time tracking').item.json.missingTrackedTime }},\n \"breakDuration\": null, \n \"startDateUtc\": \"{{ $now.setZone('Europe/Berlin').minus($('Calculate time for added time tracking').item.json.missingTrackedTime,'seconds').startOf('day').toISO() }}\",\n \"startTimeUtc\": \"{{ $now.minus($('Calculate time for added time tracking').item.json.missingTrackedTime,'seconds').format('HH:mm:ii') }}\",\n \"typeOfWorkId\": \"{{ $('Load system type of work').item.json.id }}\",\n \"userId\": \"{{ $('Workflow config').item.json.systemTimeUserId }}\"\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": "7fc1be75-da5a-4dc0-8487-8dc415e0c9b5",
"name": "如果2",
"type": "n8n-nodes-base.if",
"position": [
2020,
1320
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "7561d64d-8d53-4fdf-aa2d-0e3c0b56cb2c",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $('Workflow config').item.json.forceStartTime }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "eca1a30d-cadd-478e-975c-6d6a7cd90e58",
"name": "便签13",
"type": "n8n-nodes-base.stickyNote",
"position": [
1940,
1240
],
"parameters": {
"color": 3,
"width": 360,
"height": 280,
"content": "### 检查是否启用了强制开始时间"
},
"typeVersion": 1
},
{
"id": "b8f00f6c-8b28-4779-8e0a-49e65f263852",
"name": "向时间跟踪条目添加开始时间",
"type": "n8n-nodes-base.httpRequest",
"position": [
2620,
1000
],
"parameters": {
"url": "=https://api.awork.com/api/v1/timeentries/{{ $('Webhook call by Awork').item.json.body.entity.id }}",
"method": "PUT",
"options": {},
"jsonBody": "={ \n \"note\": \"{{ $('Webhook call by Awork').item.json.body.entity.note }} ({{ $('Workflow config').item.json.forceStartTimeText }})\",\n \"timezone\": \"{{ $('Workflow config').item.json.timeZone }}\",\n \"startDateUtc\": \"{{ $now.setZone('Europe/Berlin').minus($('Webhook call by Awork').item.json.body.entity.duration,'seconds').startOf('day').toISO() }}\",\n \"startTimeUtc\": \"{{ $now.minus($('Webhook call by Awork').item.json.body.entity.duration,'seconds').format('HH:mm:ii') }}\",\n \"duration\": {{ $('Webhook call by Awork').item.json.body.entity.duration }},\n \"typeOfWorkId\": \"{{ $('Webhook call by Awork').item.json.body.entity.typeOfWork.id }}\",\n \"userId\": \"{{ $('Webhook call by Awork').item.json.body.entity.user.id }}\" \n}",
"sendBody": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "9d0FyCu0IlwrdNkM",
"name": "Awork Api"
}
},
"retryOnFail": true,
"typeVersion": 4.2,
"waitBetweenTries": 2000
},
{
"id": "67279685-ad5d-4481-931a-3174e2493a60",
"name": "便签27",
"type": "n8n-nodes-base.stickyNote",
"position": [
2480,
880
],
"parameters": {
"color": 4,
"width": 380,
"height": 280,
"content": "### 向时间跟踪添加开始时间"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"If": {
"main": [
[
{
"node": "Check tracked time",
"type": "main",
"index": 0
}
]
]
},
"If1": {
"main": [
[
{
"node": "Load system type of work",
"type": "main",
"index": 0
}
]
]
},
"If2": {
"main": [
[
{
"node": "Add start time to time tracking entry",
"type": "main",
"index": 0
}
],
[
{
"node": "Check if min time tracking OR time tracking cleanup is enabled",
"type": "main",
"index": 0
}
]
]
},
"Switch": {
"main": [
[
{
"node": "Check if task done",
"type": "main",
"index": 0
}
],
[
{
"node": "If1",
"type": "main",
"index": 0
}
]
]
},
"Workflow config": {
"main": [
[
{
"node": "Fetch task changes",
"type": "main",
"index": 0
}
]
]
},
"Check if task done": {
"main": [
[
{
"node": "Check if force time tracking enabled",
"type": "main",
"index": 0
}
]
]
},
"Check tracked time": {
"main": [
[
{
"node": "Calculate time for added time tracking",
"type": "main",
"index": 0
}
],
[
{
"node": "Calculate time for added time tracking1",
"type": "main",
"index": 0
}
]
]
},
"Fetch task changes": {
"main": [
[
{
"node": "Split out task changes",
"type": "main",
"index": 0
}
]
]
},
"Check tag restriction": {
"main": [
[
{
"node": "Process tags and check if found in configured tags",
"type": "main",
"index": 0
}
],
[
{
"node": "Roll back task status from done to previous state1",
"type": "main",
"index": 0
}
]
]
},
"Webhook call by Awork": {
"main": [
[
{
"node": "Workflow config",
"type": "main",
"index": 0
}
]
]
},
"Check tag restriction1": {
"main": [
[
{
"node": "Process tags and check if found in configured tags1",
"type": "main",
"index": 0
}
],
[
{
"node": "Check tracked time",
"type": "main",
"index": 0
}
]
]
},
"Split out task changes": {
"main": [
[
{
"node": "Filter task status change",
"type": "main",
"index": 0
}
]
]
},
"Load system type of work": {
"main": [
[
{
"node": "Load task details for time tracking item",
"type": "main",
"index": 0
}
]
]
},
"Filter task status change": {
"main": [
[
{
"node": "Switch",
"type": "main",
"index": 0
}
]
]
},
"Check if comments are enabled": {
"main": [
[
{
"node": "Add comment to tasks",
"type": "main",
"index": 0
}
]
]
},
"Check if comments are enabled1": {
"main": [
[
{
"node": "Add comment to tasks1",
"type": "main",
"index": 0
}
]
]
},
"Check if tags listed in config node": {
"main": [
[
{
"node": "Roll back task status from done to previous state",
"type": "main",
"index": 0
}
]
]
},
"Check if force time tracking enabled": {
"main": [
[
{
"node": "Check tag restriction",
"type": "main",
"index": 0
}
],
[]
]
},
"Add start time to time tracking entry": {
"main": [
[
{
"node": "Check if min time tracking OR time tracking cleanup is enabled",
"type": "main",
"index": 0
}
]
]
},
"Calculate time for added time tracking": {
"main": [
[
{
"node": "Add tracked time to match min time settings",
"type": "main",
"index": 0
}
]
]
},
"Calculate time for added time tracking1": {
"main": [
[
{
"node": "Roll back task status from done to previous state4",
"type": "main",
"index": 0
}
]
]
},
"Load task details for time tracking item": {
"main": [
[
{
"node": "If2",
"type": "main",
"index": 0
}
]
]
},
"Roll back task status from done to previous state": {
"main": [
[
{
"node": "Check if comments are enabled",
"type": "main",
"index": 0
}
]
]
},
"Process tags and check if found in configured tags": {
"main": [
[
{
"node": "Check if tags listed in config node",
"type": "main",
"index": 0
}
]
]
},
"Roll back task status from done to previous state1": {
"main": [
[
{
"node": "Check if comments are enabled1",
"type": "main",
"index": 0
}
]
]
},
"Roll back task status from done to previous state4": {
"main": [
[]
]
},
"Process tags and check if found in configured tags1": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Check if min time tracking OR time tracking cleanup is enabled": {
"main": [
[
{
"node": "Check tag restriction1",
"type": "main",
"index": 0
}
],
[]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - IT 运维
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
完成Awork任务前检查依赖关系(变通方案)
完成Awork任务前检查依赖关系(变通方案)
If
Set
Code
+6
44 节点Gregor
IT 运维
使用GPT-4.1、Outlook和Mem.ai自动化Microsoft Teams会议分析
使用GPT-4.1、Outlook和Mem.ai自动化Microsoft Teams会议分析
If
Set
Code
+19
61 节点Wayne Simpson
人力资源
自动化Airtable到Postgres迁移,使用n8n
自动化Airtable到Postgres迁移,使用n8n
If
Set
Code
+9
66 节点Imperol
IT 运维
获取所有Scaleway服务器信息副本
通过动态筛选获取Scaleway服务器信息
If
Set
Code
+7
24 节点Pablo
工程
📊 WhatsApp和Telegram的AI令牌追踪器 - 将AI使用情况保存到Google表格
📊 WhatsApp和Telegram的AI令牌追踪器 - 将AI使用情况保存到Google表格
If
Set
Code
+15
37 节点Amanda Benks
财务
潜在客户开发与邮件工作流
使用Google Maps、SendGrid和AI自动化B2B潜在客户开发与邮件营销
If
Set
Code
+21
141 节点Ezema Kingsley Chibuzo
潜在客户开发