{
  "name": "Automate time tracking enforcement & cleanup for Awork tasks",
  "nodes": [
    {
      "id": "179c1408-eeb6-48e3-a345-4b9b1869858b",
      "name": "Workflow config",
      "type": "n8n-nodes-base.set",
      "position": [
        -780,
        700
      ]
    },
    {
      "id": "3e7a91e0-b098-4b1e-b4f8-34e83457c5e1",
      "name": "Fetch task changes",
      "type": "n8n-nodes-base.set",
      "position": [
        -360,
        700
      ]
    },
    {
      "id": "511f086c-d49f-4ed6-8bf5-73ac32546323",
      "name": "Split out task changes",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -140,
        700
      ]
    },
    {
      "id": "9b5e7bc8-2c9d-4477-bf9a-89016a289e7b",
      "name": "Filter task status change",
      "type": "n8n-nodes-base.filter",
      "position": [
        80,
        700
      ]
    },
    {
      "id": "0709319c-03ed-49f7-b9ef-479cf2a2d7e0",
      "name": "Check if task done",
      "type": "n8n-nodes-base.if",
      "position": [
        940,
        60
      ]
    },
    {
      "id": "f516a0c5-098b-49c4-8d7c-efd024da4a0c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2080,
        40
      ],
      "parameters": {
        "width": 880,
        "height": 1900,
        "content": "## Enhanced time tracking features for awork\n\nThis workflow offers several additional features for time tracking with [https://www.awork.com](https://www.awork.com):\n\n* Check whether time has been tra"
      }
    },
    {
      "id": "215d70e6-5ae9-4342-9b15-54459e96252f",
      "name": "Webhook call by Awork",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1080,
        700
      ]
    },
    {
      "id": "0674b425-48b5-44c1-8a4c-18446eed49ee",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        600
      ],
      "parameters": {
        "width": 360,
        "height": 280,
        "content": "### Workflow config\n* Configure basic settings"
      }
    },
    {
      "id": "9b085c61-09af-4ee4-8e0b-17c97e46d17b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        600
      ],
      "parameters": {
        "width": 660,
        "height": 280,
        "content": "### Extract status changes from webhook call payload\n"
      }
    },
    {
      "id": "136ad4d1-aaab-4c5e-87aa-2ebbb90f015c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        -40
      ],
      "parameters": {
        "width": 340,
        "height": 280,
        "content": "### Check if task status is currently \"done\"\n* If yes, proceed\n* If no, exit workflow"
      }
    },
    {
      "id": "9d5c4669-a5ee-4824-94aa-df6b2cc56809",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        -40
      ],
      "parameters": {
        "width": 380,
        "height": 280,
        "content": "### Check if force time tracking is enabled and no time is tracked\n* If yes, roll back task status\n* If no, check if time tracking cleaning is enabled"
      }
    },
    {
      "id": "9d0261e8-4aa2-4517-aa21-8a1a8d669e4b",
      "name": "Sticky Note22",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -980,
        40
      ],
      "parameters": {
        "width": 280,
        "height": null,
        "content": "## Green sticky notes: Logical group of nodes"
      }
    },
    {
      "id": "390668f3-be8e-435b-b587-b8051602cb24",
      "name": "Sticky Note23",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -620,
        40
      ],
      "parameters": {
        "width": 280,
        "height": null,
        "content": "## Red sticky notes: Routing and possible workflow exit"
      }
    },
    {
      "id": "06b9eb83-b591-4533-b25a-6c3137dedd27",
      "name": "Check if force time tracking enabled",
      "type": "n8n-nodes-base.if",
      "position": [
        1420,
        60
      ]
    },
    {
      "id": "4ca7bf23-1aae-4f02-be65-c73b95d7267a",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1780,
        -40
      ],
      "parameters": {
        "width": 360,
        "height": 280,
        "content": "### Check if force time tracking is limited to specific tags\n* If yes, check task tags\n* If no, roll back task status"
      }
    },
    {
      "id": "b5ef7954-3afa-476c-94da-a20e86a2307f",
      "name": "Process tags and check if found in configured tags",
      "type": "n8n-nodes-base.code",
      "position": [
        2560,
        -400
      ]
    },
    {
      "id": "9495c5fa-a1f0-4ee6-8aee-8d50b34e3f62",
      "name": "Sticky Note18",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2440,
        -520
      ],
      "parameters": {
        "width": 360,
        "height": 340,
        "content": "### Process task tags\n* If a task tag is listed in \"Limit forced time tracking to tags\", return true\n* If not found, return false"
      }
    },
    {
      "id": "476d35a9-2d22-42c6-8da6-e6c19b551ce6",
      "name": "Sticky Note19",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2920,
        -520
      ],
      "parameters": {
        "width": 400,
        "height": 340,
        "content": "### Check if at least one task tag is listed in config node\n* If yes, roll back task status\n* If not, continue workflow"
      }
    },
    {
      "id": "73b880a2-a517-409a-81b4-0b8864077ce6",
      "name": "Check if tags listed in config node",
      "type": "n8n-nodes-base.if",
      "position": [
        3060,
        -400
      ]
    },
    {
      "id": "f3abc505-6c3c-4651-9442-0888c90a6b94",
      "name": "Sticky Note20",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3440,
        -520
      ],
      "parameters": {
        "width": 360,
        "height": 340,
        "content": "### Roll back task status"
      }
    },
    {
      "id": "65aaba6d-e2ce-4563-ad98-80f960588d10",
      "name": "Sticky Note21",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3900,
        -520
      ],
      "parameters": {
        "width": 400,
        "height": 340,
        "content": "### Check if comment should be added to task\n* Exit workflow if no comment should be added"
      }
    },
    {
      "id": "90e2355d-f1ab-4b8a-badc-759f5ce92bec",
      "name": "Check if comments are enabled",
      "type": "n8n-nodes-base.if",
      "position": [
        4060,
        -420
      ]
    },
    {
      "id": "16c319d2-c0bb-4746-9716-e8979415144f",
      "name": "Sticky Note24",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4400,
        -520
      ],
      "parameters": {
        "width": 460,
        "height": 340,
        "content": "### Add comment to task regarding roll back of task state\n* Add comment and exit workflow"
      }
    },
    {
      "id": "d585a9ae-453a-4ac3-ae01-974683ae8db6",
      "name": "Add comment to tasks",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4580,
        -420
      ]
    },
    {
      "id": "ca27d942-452c-4d74-95c1-062e8efa3878",
      "name": "Roll back task status from done to previous state",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3560,
        -420
      ]
    },
    {
      "id": "546c19a9-d666-43ca-b796-c4051aea1e79",
      "name": "Check tag restriction",
      "type": "n8n-nodes-base.if",
      "position": [
        1880,
        80
      ]
    },
    {
      "id": "f40cd133-4cb2-4c3c-857e-52dfbe5f41ee",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3060,
        1240
      ],
      "parameters": {
        "width": 360,
        "height": 280,
        "content": "### Check if min time tracking OR time tracking cleanup is enabled\n* If yes, check time tracked\n* If no, exit workflow"
      }
    },
    {
      "id": "abd49a4a-4837-4070-9fe9-1de7a47aa15f",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5080,
        1240
      ],
      "parameters": {
        "width": 380,
        "height": 280,
        "content": "### Check if tracked time is lesser than min time\n* If yes, add new time tracking record to match min time in sum\n* If no, continue workflow"
      }
    },
    {
      "id": "75a23ae3-4970-48da-8a18-192f7f7d6708",
      "name": "Check tracked time",
      "type": "n8n-nodes-base.if",
      "position": [
        5220,
        1380
      ]
    },
    {
      "id": "a1c8d19e-34a4-4eed-8ab7-b1bc72758f66",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2440,
        160
      ],
      "parameters": {
        "width": 360,
        "height": 320,
        "content": "### Roll back task status"
      }
    },
    {
      "id": "c04685af-e198-4272-93d3-b0bbd7f3a94a",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2900,
        160
      ],
      "parameters": {
        "width": 400,
        "height": 320,
        "content": "### Check if comment should be added to task\n* Exit workflow if no comment should be added"
      }
    },
    {
      "id": "e7c2f529-ee42-4417-a92e-b1c0b255fccf",
      "name": "Check if comments are enabled1",
      "type": "n8n-nodes-base.if",
      "position": [
        3060,
        260
      ]
    },
    {
      "id": "21de0e65-7bb2-48a4-90f5-836758322b03",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3400,
        160
      ],
      "parameters": {
        "width": 460,
        "height": 320,
        "content": "### Add comment to task regarding roll back of task state\n* Add comment and exit workflow"
      }
    },
    {
      "id": "12e1a026-3b5a-4cd3-94ea-8892145ec9ec",
      "name": "Add comment to tasks1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3580,
        260
      ]
    },
    {
      "id": "8d83c66e-1e1a-47d7-ada6-894816906875",
      "name": "Roll back task status from done to previous state1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2560,
        260
      ]
    },
    {
      "id": "07ded81a-712f-49a9-8e76-8eb716cc99d7",
      "name": "Calculate time for added time tracking",
      "type": "n8n-nodes-base.code",
      "position": [
        5720,
        1160
      ]
    },
    {
      "id": "a5332052-88fb-4eea-9e9f-4ac5ad1920b3",
      "name": "Calculate time for added time tracking1",
      "type": "n8n-nodes-base.code",
      "position": [
        5680,
        1620
      ]
    },
    {
      "id": "d4a81a5f-f1a4-4232-a431-707716279840",
      "name": "Roll back task status from done to previous state4",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        6060,
        1620
      ]
    },
    {
      "id": "21b57017-94b3-4fff-b30a-1ec90c1224dc",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5600,
        1060
      ],
      "parameters": {
        "width": 660,
        "height": 280,
        "content": "### Calculate missing tracked time and add system generated time tracking to task\n\n"
      }
    },
    {
      "id": "252f676f-6d13-401d-b409-ec7dc07c1313",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5600,
        1540
      ],
      "parameters": {
        "width": 660,
        "height": 280,
        "content": "### Update tracked time to match time tracking intervals\n\n"
      }
    },
    {
      "id": "622e08a4-6754-4578-9bca-daf2450c061b",
      "name": "Check if min time tracking OR time tracking cleanup is enabled",
      "type": "n8n-nodes-base.if",
      "position": [
        3140,
        1340
      ]
    },
    {
      "id": "953b4ce3-ca3d-4e43-b72a-75274215682d",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3580,
        1240
      ],
      "parameters": {
        "width": 360,
        "height": 280,
        "content": "### Check if min time tracking is limited to specific tags\n* If yes, check task tags\n* If no, continue workflow"
      }
    },
    {
      "id": "7b334938-3a49-4b63-a215-5b65a576ceb7",
      "name": "Check tag restriction1",
      "type": "n8n-nodes-base.if",
      "position": [
        3680,
        1360
      ]
    },
    {
      "id": "7b238335-f3b4-417a-8b94-a5f538719205",
      "name": "Process tags and check if found in configured tags1",
      "type": "n8n-nodes-base.code",
      "position": [
        4220,
        1080
      ]
    },
    {
      "id": "e9aa2e6b-9ceb-4f09-9bab-4d984b395b89",
      "name": "Sticky Note25",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4080,
        980
      ],
      "parameters": {
        "width": 380,
        "height": 280,
        "content": "### Process task tags\n* If a task tag is listed in \"Limit min time tracking to tags\", return true\n* If not found, return false"
      }
    },
    {
      "id": "ef5df167-732f-4ae4-9e8e-84177b70ff9c",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        4720,
        1080
      ]
    },
    {
      "id": "b9043a45-2643-4160-8997-2a8ce936e0d0",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        300,
        700
      ]
    },
    {
      "id": "186b00a1-e27d-466a-a838-5c9f5755546b",
      "name": "Load task details for time tracking item",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1580,
        1320
      ]
    },
    {
      "id": "f7516774-cc65-468a-93e5-8ea7b8157d0e",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4580,
        980
      ],
      "parameters": {
        "width": 380,
        "height": 280,
        "content": "### Check if task should be time tracked by tag\n* If yes, continue\n* If no, exit workflow"
      }
    },
    {
      "id": "2262bfbf-3413-4686-892f-9072d688bd66",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        860,
        1340
      ]
    },
    {
      "id": "891c6828-17a9-4c99-b616-9fbe9fc8b5e9",
      "name": "Load system type of work",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1320,
        1320
      ]
    },
    {
      "id": "91b17bed-b86f-4345-9ec8-76b943e989ae",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        740,
        1240
      ],
      "parameters": {
        "width": 360,
        "height": 280,
        "content": "### Check if added time tracking is not system generated to prevent endless loops\n* If yes, check time tracked\n* If no, exit workflow"
      }
    },
    {
      "id": "d866932b-0e94-4a8c-acc6-62c470ac316e",
      "name": "Sticky Note26",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        1240
      ],
      "parameters": {
        "width": 560,
        "height": 280,
        "content": "### Load system type of work and related task data"
      }
    },
    {
      "id": "56edd5c1-f352-457a-9d81-1a5af8db3d9e",
      "name": "Add tracked time to match min time settings",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        6040,
        1160
      ]
    },
    {
      "id": "7fc1be75-da5a-4dc0-8487-8dc415e0c9b5",
      "name": "If2",
      "type": "n8n-nodes-base.if",
      "position": [
        2020,
        1320
      ]
    },
    {
      "id": "eca1a30d-cadd-478e-975c-6d6a7cd90e58",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1940,
        1240
      ],
      "parameters": {
        "width": 360,
        "height": 280,
        "content": "### Check if forced start time is enabled\n* If yes, update start time in tracked time\n* If no, continue"
      }
    },
    {
      "id": "b8f00f6c-8b28-4779-8e0a-49e65f263852",
      "name": "Add start time to time tracking entry",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2620,
        1000
      ]
    },
    {
      "id": "67279685-ad5d-4481-931a-3174e2493a60",
      "name": "Sticky Note27",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2480,
        880
      ],
      "parameters": {
        "width": 380,
        "height": 280,
        "content": "### Add start time to time tracking \n* Calculates start time based on duration in the past until now.\n* Updates time tracking entry and appends note to time tracking text"
      }
    }
  ],
  "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
          }
        ],
        []
      ]
    }
  }
}