> For the complete documentation index, see [llms.txt](https://docs.api.intratool.de/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.api.intratool.de/api-reference/forms/default-value-sources.md).

# DefaultValueSources

## Introduction

`DefaultValueSources` resolve prefilled values for [FormFields](/api-reference/forms/form-fields.md).

## Model Definition

**Alias**

`defaultValueSource`

**Relations**

| Key            | Relation                                                                     | Type       | Relation Field(s)                        |
| -------------- | ---------------------------------------------------------------------------- | ---------- | ---------------------------------------- |
| `formField`    | [FormField](/api-reference/forms/form-fields.md)                             | Belongs to | `form_field_id`                          |
| `sourceEntity` | [FormField](/api-reference/forms/form-fields.md) or another supported entity | Morph to   | `source_entity_type`, `source_entity_id` |

## Resolve Form Default Values

Resolve default values for all fields of one `Form`.

**Definition**

<mark style="color:green;">`GET`</mark> `/api/forms/{form}/default-values`

**Route Parameters**

| Parameter | Type      | Description |
| --------- | --------- | ----------- |
| `form`    | `integer` | Form ID.    |

**Behavior**

Sources are evaluated by `sort_number` per field. The first resolvable source wins, and response keys are form field IDs.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/forms/21/default-values', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "301": {
    "value": "ada@example.com",
    "request_value": "ada@example.com",
    "additional_information": null
  },
  "302": {
    "value": "7",
    "request_value": "7",
    "additional_information": {
      "title": "Ada Lovelace"
    }
  }
}
```

## Admin: List Source Form Fields

List accessible source `FormFields` from administrable [Forms](/api-reference/forms/forms.md) and [TaskTemplates](/api-reference/tasks-2/task-templates.md) for a field-value default source.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/forms/fields/default-value-sources/form-field-value/form-fields`

**Request Keys**

| Key        | Type      | Default        | Description                                 |
| ---------- | --------- | -------------- | ------------------------------------------- |
| `page`     | `integer` | `1`            | Result page.                                |
| `per_page` | `integer` | Server default | Results per page.                           |
| `filter`   | `object`  | No filters     | Filters applied to available source fields. |

**Behavior**

* Fields are returned only when the authenticated user can administer their parent Form or TaskTemplate.
* Each preview uses the field name as `title`, the localized parent type as `sub_title`, and the parent title as `description`.
* This endpoint uses [count-less pagination](/introduction/query-manipulation/result-control.md#count-less-pagination), so `total` is `null`.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/administration/forms/fields/default-value-sources/form-field-value/form-fields', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'page' => 1,
        'per_page' => 2,
        'filter' => [

        ]
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "current_page": 1,
  "data": [
    {
      "id": 301,
      "title": "Full name",
      "sub_title": "Form",
      "description": "Employee Feedback",
      "additional_data": {
        "source_entity_type": "formField",
        "form_type": "form",
        "form_id": 21,
        "form_field_type_id": "text",
        "sort_number": 1
      }
    },
    {
      "id": 302,
      "title": "Inspection result",
      "sub_title": "Task template",
      "description": "Equipment Inspection",
      "additional_data": {
        "source_entity_type": "formField",
        "form_type": "taskTemplate",
        "form_id": 22,
        "form_field_type_id": "boolean",
        "sort_number": 2
      }
    }
  ],
  "per_page": 2,
  "total": null
}
```

## Admin: List Source Field Filters

List filters for accessible source `FormFields`.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/forms/fields/default-value-sources/form-field-value/form-fields/filters`

**Request Keys**

| Key        | Type      | Default        | Description                                 |
| ---------- | --------- | -------------- | ------------------------------------------- |
| `page`     | `integer` | `1`            | Result page.                                |
| `per_page` | `integer` | Server default | Results per page.                           |
| `filter`   | `object`  | No filters     | Filters applied to available source fields. |

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/administration/forms/fields/default-value-sources/form-field-value/form-fields/filters', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'filter' => [

        ]
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "data": [
    {
      "key": "form_type",
      "label": "Template Type",
      "type": "multi-select",
      "operators": [
        "in",
        "not_in"
      ]
    },
    {
      "key": "form_id",
      "label": "Template",
      "type": "multi-select",
      "operators": [
        "in",
        "not_in"
      ]
    }
  ]
}
```

## Admin: List Source Field Filter Options

List options for one source-field filter.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/forms/fields/default-value-sources/form-field-value/form-fields/filters/{filterKey}/options`

**Route Parameters**

| Parameter   | Type     | Description              |
| ----------- | -------- | ------------------------ |
| `filterKey` | `string` | Multi-select filter key. |

**Request Keys**

| Key        | Type      | Default        | Description                                |
| ---------- | --------- | -------------- | ------------------------------------------ |
| `page`     | `integer` | `1`            | Result page.                               |
| `per_page` | `integer` | Server default | Results per page.                          |
| `filter`   | `object`  | No filters     | Filters applied before option aggregation. |

**Behavior**

This endpoint uses [count-less pagination](/introduction/query-manipulation/result-control.md#count-less-pagination), so `total` is `null`.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/administration/forms/fields/default-value-sources/form-field-value/form-fields/filters/form_id/options', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'page' => 1,
        'per_page' => 2,
        'filter' => [
            'form_type' => ['in' => 'form']
        ]
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "current_page": 1,
  "data": [
    {
      "value": 21,
      "label": "Employee Feedback",
      "additionalData": {
        "form_type": "form"
      }
    },
    {
      "value": 22,
      "label": "Equipment Request",
      "additionalData": {
        "form_type": "form"
      }
    }
  ],
  "per_page": 2,
  "total": null
}
```

## Admin: Create

Create a new `DefaultValueSource`.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/forms/fields/default-value-sources`

**Request Keys**

| Key                  | Type                | Default      | Description                                                    |
| -------------------- | ------------------- | ------------ | -------------------------------------------------------------- |
| `source_type`\*      | `string`            | -            | `formFieldValue` or `systemVariable`.                          |
| `form_field_id`\*    | `integer`           | -            | Target [FormField](/api-reference/forms/form-fields.md) ID.    |
| `config`             | `object`            | Type default | Source-specific configuration.                                 |
| `source_entity_type` | `string` \| `null`  | `null`       | Source morph alias, normally `formField` for `formFieldValue`. |
| `source_entity_id`   | `integer` \| `null` | `null`       | Source entity ID; required with `source_entity_type`.          |
| `sort_number`        | `integer`           | Auto         | Evaluation order within the target field.                      |

Keys with `*` are required.

**Behavior**

For `systemVariable`, `config.variable_key` is required and `config.variable_filter` may contain a [formatter](/introduction/system-variables/formatters.md). For `formFieldValue`, identify the source field through the morph keys.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/administration/forms/fields/default-value-sources', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'source_type' => 'systemVariable',
        'form_field_id' => 301,
        'config' => [
            'variable_key' => 'system.user.email',
            'variable_filter' => null
        ],
        'sort_number' => 1
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 52,
    "form_field_id": 301,
    "source_type": "systemVariable",
    "config": {
      "variable_key": "system.user.email",
      "variable_filter": null
    },
    "source_entity_type": null,
    "source_entity_id": null,
    "sort_number": 1
  }
}
```

## Admin: Update

Update an existing `DefaultValueSource`.

**Definition**

<mark style="color:blue;">`PUT`</mark> `/api/administration/forms/fields/default-value-sources/{defaultValueSource}`

**Route Parameters**

| Parameter            | Type      | Description |
| -------------------- | --------- | ----------- |
| `defaultValueSource` | `integer` | Source ID.  |

**Request Keys**

| Key                  | Type                | Default                 | Description                    |
| -------------------- | ------------------- | ----------------------- | ------------------------------ |
| `source_type`        | `string`            | Current value           | New source type.               |
| `form_field_id`      | `integer`           | Current value           | New target field ID.           |
| `config`             | `object`            | Current or type default | Source-specific configuration. |
| `source_entity_type` | `string` \| `null`  | Current value           | New source morph alias.        |
| `source_entity_id`   | `integer` \| `null` | Current value           | New source entity ID.          |
| `sort_number`        | `integer`           | Current value           | Evaluation order.              |

**Behavior**

When `source_type` changes and `config` is omitted, the new type's default configuration is used.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('PUT', '/api/administration/forms/fields/default-value-sources/52', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'source_type' => 'formFieldValue',
        'config' => [

        ],
        'source_entity_type' => 'formField',
        'source_entity_id' => 302
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": {
    "id": 52,
    "form_field_id": 301,
    "source_type": "formFieldValue",
    "config": {},
    "source_entity_type": "formField",
    "source_entity_id": 302,
    "sort_number": 1
  }
}
```

## Admin: Delete

Delete an existing `DefaultValueSource`.

**Definition**

<mark style="color:red;">`DELETE`</mark> `/api/administration/forms/fields/default-value-sources/{defaultValueSource}`

**Route Parameters**

| Parameter            | Type      | Description |
| -------------------- | --------- | ----------- |
| `defaultValueSource` | `integer` | Source ID.  |

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('DELETE', '/api/administration/forms/fields/default-value-sources/52', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "status": "success",
  "data": null
}
```
