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

# Create or Update Data Source

> Write a finished task's values into a data source record, creating it or updating the existing one.

**Create or Update Data Source** writes the values of a finished task into a [data source](https://docsy3.mile.app/pages/workflow/data-source/introduction.md). It finds the record by its Title: if a record with the same Title already exists, it is updated; otherwise a new record is created. Field work keeps your master data current: customer addresses, stock counts, service history, sales leads.

Available for: **On Task Finished** only, because it needs the task's complete data.

> [!NOTE]
>
> Required permission:
>
> * View automation
> * Create automation

## Automation detail

![Create or Update Data Source detail](https://mintcdn.com/mile-app/JlYib2YfcGFk65pR/images/v4/workflow/automation/action-create-or-update-data-source.png?fit=max\&auto=format\&n=JlYib2YfcGFk65pR\&q=85\&s=c0958d134aa3072b6fdc8b12add29b5e)

1. **Data Type**: required. It lists only the data types the selected flow uses as a data source, for example **Store**. If the flow uses none, the list says *This flow doesn't use a data source yet. Add one in the flow first.* See [Flow Configuration › Data source](https://docsy3.mile.app/pages/workflow/flow/configuration.md#data-source).
2. **Title**: required. Pick the flow field whose value finds the record. The record is created if none has that Title, and updated otherwise.
3. **Field Mapping**: the other fields of the data type. For each one, type a fixed value or click the search icon to copy a field of the finished task, exactly as in [Create Task](https://docsy3.mile.app/pages/workflow/automation/actions/create-task.md#filling-a-field). If the flow has no data source fields, the **Data Source** tab of the value picker says so.

![Create or Update Data Source settings](https://mintcdn.com/mile-app/JlYib2YfcGFk65pR/images/v4/workflow/data/automation-data-source-title.png?fit=max\&auto=format\&n=JlYib2YfcGFk65pR\&q=85\&s=97d76393b0ac9f50d2c8eb31790b9ea1)

*The Title select picks the flow field that finds the record.*

![Data Source tab with nothing to pick](https://mintcdn.com/mile-app/JlYib2YfcGFk65pR/images/v4/workflow/data/automation-value-picker-empty.png?fit=max\&auto=format\&n=JlYib2YfcGFk65pR\&q=85\&s=1657e2f13fa00e8b745bb1a8a4349f91)

*The Data Source tab explains when the flow has no data source fields.*

4. **Data Source Access**: shown only for data types with **Scope Data by User** on. Tick it to control who can see the records this automation writes, then choose how:
   * **Update**: add the chosen users to the record's existing access list.
   * **Replace**: replace the record's access list with the chosen users.
5. **Scope Data by User**: who gets access. Either one option from **Auto scope data based on**, which takes the person from the task when it runs:

   * **Same assignee**: the user assigned to the task.
   * **Assigned by**: the user who assigned it.
   * **Done by**: the user who finished it.

   or one or more named users from the **User** group.

## How it works

1. A task of the automation's flow is finished, and the [rules](https://docsy3.mile.app/pages/workflow/automation/rules.md), if any, are checked.
2. The value of the task field chosen in **Title** is looked up in the data type.
3. **A record with that Title exists**: it is updated with the mapped values. Fields that aren't mapped keep their values.
4. **No record has that Title**: a new record is created with the mapped values.

> [!NOTE]
>
> * Pick a task field in **Title**. Without it, records can't be matched.
> * The Title is matched exactly, including upper and lower case.
> * Required fields of the data type must get a value, fixed or copied.
> * The data type's field validation applies.
> * A **Relation** field takes the ID of the linked record, not its Title.

## Examples

**Customer database after delivery**

| Setting | Value |
| - | - |
| Event | On Task Finished |
| Flow | Delivery |
| Data Type | Customer Database |
| Title | Customer Name (from Delivery) |
| Customer Address | Customer Address (from Delivery) |
| Customer Coordinate | Delivery Coordinate (from Delivery) |
| Customer Phone | Customer Phone (from Delivery) |

**Inventory after a stock check**

| Setting | Value |
| - | - |
| Flow | Stock Inspection |
| Data Type | Inventory Database |
| Title | Product ID |
| Product Name | Inspected Product |
| Current Stock | Stock Count |
| Warehouse Location | Inspection Location |

**Service history**

| Setting | Value |
| - | - |
| Flow | Home Cleaning |
| Data Type | Service History |
| Title | Service ID |
| Customer Name | Customer Name |
| Service Type | Service Category |

**Sales leads from canvassing**

| Setting | Value |
| - | - |
| Flow | Field Canvassing |
| Data Type | Sales Leads |
| Title | Prospect Name |
| Contact Number | Phone Number |
| Interest Level | Survey Result |
| Data Source Access | Update, Scope Data by User: Done by (the canvasser sees their own leads) |

## Good practice

* Choose a Title field that really is unique, such as a customer ID or order number.
* Prefer copied values over typed ones, and map only fields that matter.
* Use [rules](https://docsy3.mile.app/pages/workflow/automation/rules.md) to write only when it makes sense, for example only successful deliveries.
* Test with a sample task, then check the record on the Data Source page and the run in the [log](https://docsy3.mile.app/pages/workflow/automation/log.md).

## Troubleshooting

**No record is created or updated.**

* Check that the automation is **Active**, the flow matches, and the rules don't exclude the task.
* Check that the task field chosen in **Title** had a value in the task.
* Check that every required field of the data type has a value.

**A new record is created every time instead of updating.** The Title value doesn't match the existing record exactly (case included), or the wrong task field is chosen in **Title**.

**Some fields don't change.** They're not mapped, or the task's field was empty.

**The wrong data type is updated.** Edit the automation and check **Data Type**; look for other automations on the same event.


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