> For the complete documentation index, see [llms.txt](https://motivlabs.gitbook.io/impulse-user-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://motivlabs.gitbook.io/impulse-user-manual/content-manipulators-motators/add-replace-field.md).

# Add Replace Field

The `add-replace-field` manipulator adds a field to the definition of a content type and, also, could replace the value of an existing field.

You can use this manipulator to copy values from an existing field in the content type or to set a default value for the new/updated field.

## Properties

It is important to note that all these `field...` (i.e. `fieldId`, `fieldType`, etc) properties are motation properties, they have to use the same syntax as the motation system. Just like the ones used in the connector's Transformers.

| Property            | Purpose                                                                                                              | Required                             |
| ------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| runManipulator      | When to run this manipulator? Set one of the following options: `ALWAYS`, `VALUE_EMPTY`, `FIELD_NOT_EXISTS`, `REGEX` | True                                 |
| runManipulatorRegex | Regular Expression to match the Field Value                                                                          | Only when `REGEX` was selected above |
| fieldId             | ID of the field to add                                                                                               | True                                 |
| fieldType           | Type of the field to add                                                                                             | True                                 |
| fieldValue          | Value to set for the field                                                                                           | True                                 |
| fieldName           | Name of the field to add                                                                                             | False                                |
| fieldSystemType     | Motation System type of the field to add                                                                             | False                                |
| fieldOrder          | Order of the field to add                                                                                            | False                                |

## Specifics

### How to use

It is very straightforward to use this manipulator. You just need to:

1. Set `runManipulator` to one of the options and set the `runManipulatorRegex` if you selected `REGEX` in the previous step. Note: if you select a non-valid option, the manipulator will select `FIELD_NOT_EXISTS` by default. The options are:
   1. `ALWAYS` will always run the manipulator.
   2. `VALUE_EMPTY` will run the manipulator only if the value of the field is empty or doesn't exist.
   3. `FIELD_NOT_EXISTS` will run the manipulator only if the field doesn't exist.
   4. `REGEX` will run the manipulator only if the value of the field matches the `runManipulatorRegex`.
2. Set the `fieldId`, `fieldType` and `fieldValue` properties. Like you would do in the motation system.

### applyOn

This manipulator can be used only on `read`

### fieldType

It could be any of the `Motation's TypeEnum`, for example: `String` `BigString` `Boolean` `Integer` `BigInteger` `Decimal` `Float` ...\
\
These Field type values are what we use in relation to our motation in order to manipulate the content these exact motation field types can be found in our [Connector Matrix](https://labs.motivops.io/)

### fieldValue

The `fieldValue` property can be set to a hardcoded value or to another field value using brackets `{{another-field-id}}`. For example, if you want to set the value of the field to the value of another field, you can do it like this:

Let's say you "Headline" at source needs to be "Headline" and "Mobile Headline" at destination. You can do it like this:

```
{
  "name": "Add-Field-Motator",
  "contentType": "voyage",
  "applyOn": "read",
  "order": 1,
  "config": {
    "runManipulator": "FIELD_NOT_EXISTS",
    "fieldId": "mobileHeadline",
    "fieldType": "String",
    "fieldValue": "{{headline}}",
    "fieldName": "Mobile Headline",
    "fieldSystemType": "Symbol",
    "fieldOrder": "2"
  }
}
```

Assuming you have a field called "Headline" in your content type, with an id of "headline", the value of the field "mobileHeadline" will be the value of the field "headline".

You could even merge fields, like this:

```
{
  "name": "Add-Field-Motator",
  "contentType": "voyage",
  "applyOn": "read",
  "order": 3,
  "config": {
    "runManipulator": "ALWAYS",
    "fieldId": "merged",
    "fieldType": "BigString",
    "fieldValue": "Merged Text: {{headline}} - {{body}}",
    "fieldName": "Merged",
    "fieldSystemType": "Text",
    "fieldOrder": "3"
  }
```

## Examples

This would be the API call for a job with this manipulator (also using Regex manipulator):

```
{
...
"mutate": {
      "motatorsBinary": [
        {
          "name": "Add-Replace-Field-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "order": 1,
          "config": {
            "runManipulator": "FIELD_NOT_EXISTS",
            "fieldId": "mobileHeadline",
            "fieldType": "String",
            "fieldValue": "{{headline}}",
            "fieldName": "Mobile Headline",
            "fieldSystemType": "Symbol",
            "fieldOrder": "1"
          }
        },
        {
          "name": "Regex-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "fieldName": "body",
          "order": 2,
          "config": {
            "regex": "dummy",
            "replace": "pretty smart"
          }
        },
        {
          "name": "Add-Replace-Field-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "order": 3,
          "config": {
            "runManipulator": "NOT_CORRECT_CONFIG",
            "fieldId": "merged",
            "fieldType": "BigString",
            "fieldValue": "Merged Text: {{headline}} - {{body}}",
            "fieldName": "Merged",
            "fieldSystemType": "Text",
            "fieldOrder": "3"
          }
        },
        {
          "name": "Add-Replace-Field-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "order": 4,
          "config": {
            "runManipulator": "VALUE_EMPTY",
            "fieldId": "emptyField",
            "fieldType": "String",
            "fieldValue": "{{headline}} -- This was empty",
            "fieldName": "Empty Field",
            "fieldSystemType": "Symbol",
            "fieldOrder": "4"
          }
        },
        {
          "name": "Add-Replace-Field-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "order": 5,
          "config": {
            "runManipulator": "VALUE_EMPTY",
            "fieldId": "notEmptyField",
            "fieldType": "String",
            "fieldValue": "{{headline}} -- This was not empty",
            "fieldName": "Not Empty Field",
            "fieldSystemType": "Symbol",
            "fieldOrder": "5"
          }
        },
        {
          "name": "Add-Replace-Field-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "order": 6,
          "config": {
            "runManipulator": "FIELD_NOT_EXISTS",
            "fieldId": "existingField",
            "fieldType": "String",
            "fieldValue": "This Field shouldn't have this value",
            "fieldName": "Existing Field",
            "fieldSystemType": "Symbol",
            "fieldOrder": "6"
          }
        },
        {
          "name": "Add-Replace-Field-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "order": 7,
          "config": {
            "runManipulator": "ALWAYS",
            "fieldId": "alwaysField",
            "fieldType": "String",
            "fieldValue": "This Field is always updated",
            "fieldName": "Always Field",
            "fieldSystemType": "Symbol",
            "fieldOrder": "7"
          }
        },
        {
          "name": "Add-Replace-Field-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "order": 8,
          "config": {
            "runManipulator": "REGEX",
            "runManipulatorRegex": "This is regex original",
            "fieldId": "regexField",
            "fieldType": "String",
            "fieldValue": "Regex value updated",
            "fieldName": "Regex Field",
            "fieldSystemType": "Symbol",
            "fieldOrder": "8"
          }
        },
        {
          "name": "Add-Replace-Field-Motator",
          "contentType": "informa",
          "applyOn": "read",
          "order": 9,
          "config": {
            "runManipulator": "REGEX",
            "runManipulatorRegex": "Not matching regex",
            "fieldId": "regexNotMatchingField",
            "fieldType": "String",
            "fieldValue": "Regex value updated",
            "fieldName": "Regex Not Matching Field",
            "fieldSystemType": "Symbol",
            "fieldOrder": "9"
          }
        }
      ]
    }
...
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://motivlabs.gitbook.io/impulse-user-manual/content-manipulators-motators/add-replace-field.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
