> ## Documentation Index
> Fetch the complete documentation index at: https://docsv4.mile.app/llms.txt
> Use this file to discover all available pages before exploring further.

# On Task Assigned

> Run an automation when a task of the chosen task type is assigned to a user.

**On Task Assigned** runs when a task of the chosen **Task Type** is assigned to a user. It marks the moment a task gets its owner, so it's the place to notify the customer that someone is on the way, prepare follow-up work or update a workforce system.

<Note>
  Required permission:

  * View automation
  * Create automation
</Note>

## When it runs

The event runs when a task is assigned by any of these:

* **Manual assignment** on the Task page of the web app.
* **Bulk assignment** of several tasks at once.
* **Routing dispatch**: tasks assigned when a routing result is dispatched.
* **Automation**: a task assigned by another automation.
* **API**: assignment through the API.

It runs only when the assignment is saved, the task's task type matches the automation's **Task Type**, and the task matches every [rule](/pages/workflow/automation/rules).

## Set it up

1. On **Workflow › Automation**, click **New**.
2. **Event**: **On Task Assigned**.
3. **Task Type**: the task type to watch.
4. **Automation Type**: one of
   * [Create Task](/pages/workflow/automation/actions/create-task)
   * [Webhook](/pages/workflow/automation/actions/webhook)
   * [Notification](/pages/workflow/automation/actions/notification)
5. Fill in the **Automation detail** and click **Submit**.

## Use cases

| Scenario | Task Type | Automation Type | Result |
| - | - | - | - |
| Prepare equipment | Installation | Create Task | A checklist task is created when the installation is assigned. |
| Sync a workforce system | Service | Webhook | The assignee and task are sent to your system. |
| Tell the customer who is coming | Delivery | Notification | The customer gets a WhatsApp message or SMS with the tracking link. |

## Webhook payload

An example request body:

```json theme={null}
{
  "event": "on_task_assigned",
  "timestamp": "2024-01-15T11:00:00.000Z",
  "task": {
    "id": "task_id_123",
    "flow": "Delivery",
    "flowId": "flow_id_456",
    "invoice": "INV-2024-001",
    "name": "Budi Santoso",
    "phone": "+6281234567890",
    "address": "Jl. Sudirman No. 123, Jakarta",
    "deliveryCoordinate": "-6.2088,106.8456",
    "startTime": "2024-01-15T14:00:00.000Z",
    "endTime": "2024-01-15T16:00:00.000Z",
    "status": "assigned",
    "priority": "normal"
  },
  "assignee": {
    "id": "user_id_789",
    "name": "Field Worker Name",
    "email": "worker@example.com",
    "phone": "+6281234567891",
    "teamId": "team_id_101"
  },
  "assigner": { "id": "user_id_102", "name": "Operations Manager", "email": "ops@example.com" },
  "hub": { "id": "hub_id_789", "name": "Jakarta Hub" },
  "assignmentTime": "2024-01-15T11:00:00.000Z"
}
```

The exact fields depend on your task type. The [automation log](/pages/workflow/automation/log) shows the exact request that was sent.

## Troubleshooting

**The automation doesn't run when tasks are assigned.**

* Check that its **Active** switch is on and the task type matches.
* Check that the rules don't exclude the task.
* Assign to a user, not only to a team: the task must become assigned.

**The webhook is called several times for one assignment.**

* Look for several active automations on the same task type.
* Make your endpoint answer with a 2xx status (200 or 204).

**The customer doesn't get the notification.**

* Check the phone number in the field chosen as **Receiver Phone Number**.
* Look at the [log](/pages/workflow/automation/log) for the failed run and its response.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.