> 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/additional-attributes/attribute-field-default-value-sources.md).

# AttributeFieldDefaultValueSources

## Introduction

`AttributeFieldDefaultValueSources` define how an [AttributeField](/api-reference/additional-attributes/attribute-fields.md) gets a prefilled value.

## Model Definition

**Source Types**

* `formFieldValue` - Copies a value from another form field.
* `systemVariable` - Resolves a value from a system variable.

## Admin: Create

Create a default value source for an attribute field.

**Definition**

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

**Request Keys**

| Key                  | Type                | Default      | Description                                                                           |
| -------------------- | ------------------- | ------------ | ------------------------------------------------------------------------------------- |
| `source_type`\*      | `string`            | -            | Selects one of the supported [Source Types](#source-types).                           |
| `form_field_id`\*    | `integer`           | -            | Target [AttributeField](/api-reference/additional-attributes/attribute-fields.md) ID. |
| `config`             | `object`            | type default | Source-specific configuration.                                                        |
| `source_entity_type` | `string` \| `null`  | `null`       | Morph alias for source entity (for field value sources typically `formField`).        |
| `source_entity_id`   | `integer` \| `null` | `null`       | Source entity ID (required with `source_entity_type`).                                |
| `sort_number`        | `integer`           | auto         | Evaluation order inside one `form_field_id`.                                          |

Keys with `*` are required.

**Behavior**

The accepted `config` keys depend on `source_type`:

* `formFieldValue`
  * no required config keys
* `systemVariable`
  * `variable_key` (required)
  * `variable_filter` (optional, formatter key)

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

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

## Admin: List source form fields

List fields from administrable [Forms](/api-reference/forms/forms.md) and [TaskTemplates](/api-reference/tasks-2/task-templates.md) that can provide a `formFieldValue` default.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/additional-attributes/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/additional-attributes/fields/default-value-sources/form-field-value/form-fields', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'page' => 1,
        'per_page' => 2,
        'filter' => [
            'form_type' => [
                'in' => 'form,taskTemplate'
            ]
        ]
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "current_page": 1,
  "data": [
    {
      "id": 27,
      "title": "Employee number",
      "sub_title": "Form",
      "description": "Employee Onboarding",
      "additional_data": {
        "source_entity_type": "formField",
        "form_type": "form",
        "form_id": 11,
        "form_field_type_id": "text",
        "sort_number": 1
      }
    },
    {
      "id": 29,
      "title": "Manager approval",
      "sub_title": "Task template",
      "description": "Onboarding Approval",
      "additional_data": {
        "source_entity_type": "formField",
        "form_type": "taskTemplate",
        "form_id": 12,
        "form_field_type_id": "entity-select",
        "sort_number": 3
      }
    }
  ],
  "per_page": 2,
  "total": null
}
```

## Admin: List source field filters

List filters available for source-field selection.

**Definition**

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

**Request Keys**

| Key      | Type     | Default    | Description                                                    |
| -------- | -------- | ---------- | -------------------------------------------------------------- |
| `filter` | `object` | No filters | Filters applied before the available filter metadata is built. |

**Example Request**

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

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

{% 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 the available options for a multi-select source-field filter.

**Definition**

<mark style="color:yellow;">`POST`</mark> `/api/administration/additional-attributes/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/additional-attributes/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,taskTemplate'
            ]
        ]
    ]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "current_page": 1,
  "data": [
    {
      "value": 11,
      "label": "Employee Onboarding",
      "additionalData": {
        "form_type": "form"
      }
    },
    {
      "value": 12,
      "label": "Onboarding Approval",
      "additionalData": {
        "form_type": "taskTemplate"
      }
    }
  ],
  "per_page": 2,
  "total": null
}
```

## Admin: Update

Update an existing default value source.

**Definition**

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

**Route Parameters**

| Parameter            | Type      | Description              |
| -------------------- | --------- | ------------------------ |
| `defaultValueSource` | `integer` | Default value source ID. |

**Request Keys**

| Key                  | Type                | Description                                                 |
| -------------------- | ------------------- | ----------------------------------------------------------- |
| `source_type`        | `string`            | Selects one of the supported [Source Types](#source-types). |
| `form_field_id`      | `integer`           | New target field ID.                                        |
| `config`             | `object`            | Source-specific configuration.                              |
| `source_entity_type` | `string` \| `null`  | New source entity type.                                     |
| `source_entity_id`   | `integer` \| `null` | New source entity ID.                                       |
| `sort_number`        | `integer`           | New evaluation order.                                       |

**Example Request**

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

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

{% endtab %}
{% endtabs %}

**Example Response**

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

## Admin: Delete

Delete an existing default value source.

**Definition**

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

**Route Parameters**

| Parameter            | Type      | Description              |
| -------------------- | --------- | ------------------------ |
| `defaultValueSource` | `integer` | Default value 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/additional-attributes/fields/default-value-sources/41', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

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