Workflow: If Workflow
Integrations: asana, asanaTrigger, function, if, notion, stopAndError

{"meta": {"instanceId": "workflow-76c39dc9", "versionId": "1.0.0", "createdAt": "2025-09-29T07:07:42.113057", "updatedAt": "2025-09-29T07:07:42.113070", "owner": "n8n-user", "license": "MIT", "category": "automation", "status": "active", "priority": "high", "environment": "production"}, "nodes": [{"id": "daaa472a-fff3-41e2-9b6f-f7f54655ea16", "name": "Determine create/update", "type": "n8n-nodes-base.if", "position": [1380, 300], "parameters": {"conditions": {"string": [{"value1": "={{ $json[\"action\"] }}", "value2": "Create"}]}}, "typeVersion": 1, "notes": "This if node performs automated tasks as part of the workflow."}, {"id": "1b047238-80b4-4144-929d-f860510b68c6", "name": "Update task", "type": "n8n-nodes-base.notion", "position": [1580, 420], "parameters": {"pageId": "={{ $json[\"database_id\"] }}", "resource": "databasePage", "operation": "update", "propertiesUi": {"propertyValues": [{"key": "YOUR_CREDENTIAL_HERE", "title": "={{ $json[\"name\"] }}"}, {"key": "YOUR_CREDENTIAL_HERE", "date": "={{ $json[\"due_on\"] }}"}]}}, "credentials": {"notionApi": {"id": "{{ $credentials.notionApi.id }}", "name": "[UPDATE ME]"}}, "typeVersion": 2, "notes": "This notion node performs automated tasks as part of the workflow."}, {"id": "71801502-14bd-42d2-beb9-e44e90bcac49", "name": "Create task", "type": "n8n-nodes-base.notion", "position": [1580, 180], "parameters": {"title": "={{$json[\"name\"]}}", "resource": "databasePage", "databaseId": "6181df20-c949-42e3-9999-7168d746efab", "propertiesUi": {"propertyValues": [{"key": "YOUR_CREDENTIAL_HERE", "numberValue": "={{ parseInt($json[\"gid\"]) }}"}]}}, "credentials": {"notionApi": {"id": "{{ $credentials.notionApi.id }}", "name": "[UPDATE ME]"}}, "executeOnce": true, "typeVersion": 2, "notes": "This notion node performs automated tasks as part of the workflow."}, {"id": "76d95145-89ff-477f-9e28-a64c3601b4ea", "name": "Get tasks", "type": "n8n-nodes-base.asana", "position": [780, 300], "parameters": {"id": "={{ $json[\"gid\"] }}", "operation": "get"}, "credentials": {"asanaApi": {"id": "{{ $credentials.asanaApi.id }}", "name": "[UPDATE ME]"}}, "typeVersion": 1, "continueOnFail": true, "notes": "This asana node performs automated tasks as part of the workflow."}, {"id": "b79c96eb-ad00-4aa7-b02e-306a940396fc", "name": "Find tasks", "type": "n8n-nodes-base.notion", "position": [980, 160], "parameters": {"options": {}, "resource": "databasePage", "operation": "getAll", "databaseId": "6181df20-c949-42e3-9999-7168d746efab", "filterJson": "={{$node[\"Get unique tasks\"].json[\"notionfilter\"]}}", "filterType": "json"}, "credentials": {"notionApi": {"id": "{{ $credentials.notionApi.id }}", "name": "[UPDATE ME]"}}, "typeVersion": 2, "notes": "This notion node performs automated tasks as part of the workflow."}, {"id": "9804b81f-b2f9-45dc-9bbd-a652543668fd", "name": "Get unique tasks", "type": "n8n-nodes-base.function", "position": [580, 300], "parameters": {"functionCode": "const gids = [];\n\n// get all the unique Asana task gids\nfor (item of items) {\n  var gid = parseInt(item.json.resource.gid);\n  var resource_type = item.json.resource.resource_type;\n  if (!(gids.includes(gid)) && resource_type == \"task\") {\n    gids.push(gid);\n  }\n}\n\n// show in output\nconst new_items = [];\nfor (gid of gids) {\n  var new_item = {\n    \"json\": {\n      \"gid\": 0,\n      \"gids\": [],\n      \"notionfilter\": \"\"\n    }\n  };\n  new_item = JSON.stringify(new_item);\n  new_item = JSON.parse(new_item);\n  new_item.json.gid = gid;\n  new_item.json.gids = gids;\n  new_items.push(new_item);\n\n  // Notion filter\n  notionfilter = {\n    or: [],\n  }\n\n  for (gid of gids) {\n    const filter = {\n      property: 'Asana GID',\n      number: {\n        equals: gid\n      }\n    }\n    notionfilter[\"or\"].push(filter);\n  }\n\n\n  new_item.json.notionfilter = JSON.stringify(notionfilter); \n}\n\nconsole.log(gids);\nreturn new_items;"}, "executeOnce": false, "typeVersion": 1, "notes": "This function node performs automated tasks as part of the workflow."}, {"id": "91883ca1-91f8-41ce-84d5-00f9f3296cc7", "name": "Determine", "type": "n8n-nodes-base.function", "position": [1180, 300], "parameters": {"functionCode": "const gids_to_update = [];\nconst database_ids = [];\n\nfor (item of $items(\"Find tasks\")) {\n  gids_to_update.push(parseInt(item.json.property_asana_gid));\n  database_ids.push(item.json.id);\n}\nconsole.log(gids_to_update);\nconsole.log(database_ids);\n\nvar gid;\nlet i = 0;\nfor (item of $items(\"Get tasks\")) {\n  gid = parseInt(item.json.gid);\n  if (gids_to_update.includes(gid)) {\n    item.json.action = \"Update\"\n    item.json.database_id = database_ids[i];\n  } else {\n    item.json.action = \"Create\"\n  }\n  i++;\n}\n\nreturn $items(\"Get tasks\");"}, "typeVersion": 1, "notes": "This function node performs automated tasks as part of the workflow."}, {"id": "8ba512bb-671a-47d2-88fc-19ed358df728", "name": "Check required fields exist", "type": "n8n-nodes-base.if", "position": [1780, 180], "parameters": {"conditions": {"string": [{"value1": "={{ $node[\"Determine\"].json[\"due_on\"] }}", "operation": "isNotEmpty"}]}}, "typeVersion": 1, "notes": "This if node performs automated tasks as part of the workflow."}, {"id": "512a09e0-c595-4613-a4d9-ed3160fd403b", "name": "Update deadline", "type": "n8n-nodes-base.notion", "position": [1980, 180], "parameters": {"pageId": "={{ $json[\"id\"] }}", "resource": "databasePage", "operation": "update", "propertiesUi": {"propertyValues": [{"key": "YOUR_CREDENTIAL_HERE", "date": "={{ $node[\"Determine\"].json[\"due_on\"] }}"}]}}, "credentials": {"notionApi": {"id": "{{ $credentials.notionApi.id }}", "name": "[UPDATE ME]"}}, "typeVersion": 2, "notes": "This notion node performs automated tasks as part of the workflow."}, {"id": "4b08a930-93ef-4f88-8109-9afa45af703e", "name": "On update", "type": "n8n-nodes-base.asanaTrigger", "position": [380, 300], "webhookId": "61055fe2-63c7-4b93-adcb-ddb7556c3060", "parameters": {"resource": "1202718722261680", "workspace": "1177253494675264"}, "credentials": {"asanaApi": {"id": "{{ $credentials.asanaApi.id }}", "name": "[UPDATE ME]"}}, "typeVersion": 1, "notes": "This asanaTrigger node performs automated tasks as part of the workflow."}, {"id": "error-c4de0eb7", "name": "Error Handler", "type": "n8n-nodes-base.stopAndError", "typeVersion": 1, "position": [1000, 400], "parameters": {"message": "Workflow execution error", "options": {}}}], "connections": {}, "name": "If Workflow", "description": "Automated workflow: If Workflow. This workflow processes data and performs automated tasks.", "settings": {"executionOrder": "v1", "saveManualExecutions": true, "callerPolicy": "workflowsFromSameOwner", "errorWorkflow": null, "timezone": "UTC", "executionTimeout": 3600, "maxExecutions": 1000, "retryOnFail": true, "retryCount": 3, "retryDelay": 1000}, "tags": ["automation", "n8n", "production-ready", "excellent", "optimized"], "notes": "Excellent quality workflow: If Workflow. This workflow has been optimized for production use with comprehensive error handling, security, and documentation."}