# How to Create a Record in Custom Data from Scenario Data?

After the user has entered data (rating after a dialog, interview date, callback contacts), you need to save it to Custom Data. The `custom_modules__set` action creates a new record from values in state variables. All input blocks before this action collect data and save it to variables of type "model_name:field_name".

---

## When Needed

- After a C-SAT survey — save rating and chat_id for analytics.
- User filled an interview or callback request — create a record for the operator to process.
- You need to save complex information about an interaction for use later in the scenario or in dashboards.

---

## What's Important to Know

- **custom_modules__set** — action for creating a new record in Custom Data.
- All input blocks before this action collect data and save it to variables of type "model_name:field_name".
- After creating the record, it is saved to the variable specified in the `set_to` parameter.
- Used for creating new records, not for updating existing ones.

---

## Prerequisites

- [x] You are logged in with integrator or administrator rights.
- [x] There is a created Custom Data model with needed fields in the system.
- [x] You have access to the scenario constructor.
- [x] You have collected data from the user in previous scenario blocks.

---

## Step-by-Step Instructions

### Preparing Data

1. In the scenario, add blocks to collect data from the user:
   - **"Wait for Response"** — for text input
   - **"Message with Keyboard"** — for selection from options
2. Make sure data is saved to variables of type "model_name:field_name" (for example, `customer:name`, `customer:email`).

### Configuring Action

1. Add an **"Action"** block to the scenario after data collection blocks.
2. In the "Action" block settings, select the **`custom_modules__set`** function.
3. In the configuration field (JSON), enter parameters:

```json
{
  "module_name": "customer",
  "set_to": "customer"
}
```

- `module_name` — name of the model with the custom table (for example, "customer", "product", "order")
- `set_to` — name of the variable where the created record will be saved (for example, "customer", "new_order")

4. Save changes in the action and scenario.

### Using Created Record

After creating the record, you can output its attributes in a message block using the variable from `set_to`. For example, if `set_to` = "customer", you can use `{{customer:name}}` or `{{customer:email}}` to output field values.

---

## Usage Example

**Scenario:**
1. "Wait for Response" block → saves to `customer:name`
2. "Wait for Response" block → saves to `customer:email`
3. "Action" block with `custom_modules__set` → creates record and saves to `customer`
4. "Message" block → outputs `{{customer:name}}` and `{{customer:email}}`

---

## Typical Scenarios

| Scenario | Model fields | Sequence |
|----------|--------------|------|
| **C-SAT / feedback** | chat_id, rating, created_at | After survey → set record → use in Metabase dashboards |
| **Interview request** | interview_date, interview_time, status | User selects date/time → set record → operator processes |
| **Callback request** | phone, preferred_time, status | User enters data → set record → later delete after completion |

---

## What Happens After

After executing the `custom_modules__set` action, a new record is created in the Custom Data table with all data collected in previous blocks. The record becomes available for viewing in the Custom Data module and can be used in other parts of the scenario through the variable from `set_to`.

---

## How to Verify It Worked

- Check that all data is collected in variables of type "model_name:field_name".
- Make sure the model name in `module_name` matches an existing model.
- Test the scenario and check that the record was created in Custom Data.
- Check that the variable from `set_to` contains the created record.

---

## Related Materials

- [Custom Data patterns and examples](/en/customdata/explanation/custom-data-patterns-and-examples.md) — how to choose the right approach
- [How to get a record from Custom Data](/en/customdata/how-to/use-custom-modules-get.md)
- [Save data from scenario](/en/customdata/how-to/save-data-from-scenario.md)
- [Create model](/en/customdata/how-to/create-model.md)

