# Update object

The Update object action updates the object class properties of objects in a data source.

## Usage

This action node is used to update properties on one or more objects in a data source.

To update many objects at once (a batch update) there are two possible methods:

1. Use a [While](/library/action-nodes/while.md) or [Foreach](/library/action-nodes/foreach.md) action node to iterate over the objects. Add an Update object action node inside the iterator action node with the same data source selected and `Object in context` as the **Selection**.
2. Use only the Update object action node. This method is more performant. See the example *Batch updat*e in the Examples section below.

When Update object operates on an object it becomes the [object in context](/reference/platform-concepts/objects.md#object-in-context). This object in context contains the original values before the update and these can be accessed using [data bindings](/reference/platform-concepts/data-bindings.md) and [functions](/reference/platform-concepts/functions.md).

In addition, the values set in the update are available as *self-properties.* Self-properties are only available in [functions](/reference/platform-concepts/functions.md). These can be used to update properties that are dependent on the values of other properties that are being updated in the same operation. In other words, a function must be used to access to new value of a property, if that property is updated in the same Update Object operations. See the example *Update Object - Self Properties and dependencies* below.

### Examples

{% tabs %}
{% tab title="A simple update" %}
In this example, 1 object is updated. The properties `Price` and `Product` (reference) of an `Order line` is updated. As you see, the `Price` on the Order line is set equal to the price of the `Product`.

<div align="left"><figure><img src="/files/MxNLhgWYoZZc6Jx0qf2S" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="Batch update" %}
This example updates the Amount property of all Order Lines. Price and Units are retrieved and the Amount is calculated independently for each record.

<div align="left"><figure><img src="/files/2v4EgFhXjAtvjF0aFEvZ" alt=""><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Value processor " %}
You may use the [value processor](/reference/platform-concepts/value-processor.md) inside the Update Object action node. For example, to increase a value by 1.

<div align="left"><figure><img src="/files/ZApCIW7KVaQ413DK4TOr" alt=""><figcaption><p>Data binding to the same property, then tick "Value Processor"</p></figcaption></figure></div>

<div align="left"><figure><img src="/files/FcZb9tWecjgXGyQj2cI5" alt=""><figcaption><p>The Value Processor setup</p></figcaption></figure></div>
{% endtab %}

{% tab title="Self properties and dependencies" %}
Imagine the following simple scenario. You want to set Property 1 to 20, and you want to set `Property 2` equal `Property 1` in the same Update Object operation

<div align="left"><figure><img src="/files/1Y0ePcXEqteqyubt4lG3" alt=""><figcaption></figcaption></figure></div>

In the above example: if both `Prop 1` and `Prop 2` was 0 by default, then `Prop 2` will still be 0 after this update. The reason is that Data Binding defaults to the *old value* of the bound property. If you want to access the *new value*, you must use a function, and add `prop1` from the Self Properties list, as illustrated below:

<div align="left"><figure><img src="/files/Ek9Bm3L9DLiX2rhzkjhN" alt=""><figcaption></figcaption></figure></div>

<figure><img src="/files/op5cEiYGusHe1pdJ5Rdh" alt=""><figcaption></figcaption></figure>

In the function editor, as in the screenshot above, you may expand the data source in the left pane and add the same property as a function parameter from there. That will imply use the old value, and not the new value (self-property).\
\
\&#xNAN;*Note that you may only add properties directly at the data source itself as self-properties, and not reference properties (e.g. if you are updating Order Line.Product and Order Line.Price in the same operation, you cannot select Order Line.Product.Product Price as self-property)*
{% endtab %}

{% tab title="Multi cardinality - Value processor" %}
Sometimes you want to update an Object Class Property having [Cardinality Many](/reference/data-model/object-class-properties.md), but you want to keep the existing list of references and add (or remove) a set of references. You can use the [Value Processor](/reference/platform-concepts/value-processor.md) for that.

<div align="left"><figure><img src="/files/tgj7mFKtNcwFewVUog2M" alt=""><figcaption><p>Data binding to the same property, then tick "Value Processor"</p></figcaption></figure></div>

<div align="left"><figure><img src="/files/AVoJM0rd5qWLLyLcEezi" alt=""><figcaption><p>When clicking "Add Selection" you may select the data source holding the references you want to add</p></figcaption></figure></div>
{% endtab %}
{% endtabs %}

### Working with schemas

Update Object can target an [action variable](/reference/actions/action-variables.md) of type [schema](/reference/platform-concepts/schemas.md). When the target is a schema, the **Values on update** section maps new values onto the schema's properties, including nested properties. If the schema is an object or an array of objects, the object(s) must be instantiated using [Create Object](/library/action-nodes/create-object.md) first. For schemas of type array, the only available selection is **All objects** — the update is applied to every object in the array. To update a specific object in an array, use a [Foreach](/library/action-nodes/foreach.md) with a condition instead.

Property-to-property mapping is supported: a value from one schema property can be mapped directly onto another schema property in the same update.

When schema data needs to be written to the database, the property values from the schema can be mapped onto an [action data source](/reference/actions/action-data-sources.md) backed by an object class using **Values on update**, in the same way as on [Create Object](/library/action-nodes/create-object.md).

{% hint style="info" %}
**Important**

When updating a nested schema path, the parent structure must already exist. If it does not, the action node raises an error. For example, updating `Company.Address.City` will fail if the `Address` object has not been created on `Company`.
{% endhint %}

## Properties

<table><thead><tr><th width="187">Property</th><th>Description</th></tr></thead><tbody><tr><td><strong>Data Source</strong></td><td>Select a data source that contains the object(s) to update.</td></tr><tr><td><strong>Selection</strong></td><td><p><em>Available if the selected</em> <strong>Data Source</strong> <em>is a many-cardinality data source.</em><br><br>Define the objects to update.</p><ul><li><code>All objects</code></li><li><a href="/spaces/-MiLU-xcHu0eLZiTxcmZ/pages/-MiR92uc7YpwXZWPxMI1#object-selection"><code>Selected object(s)</code></a></li><li><a href="/spaces/-MiLU-xcHu0eLZiTxcmZ/pages/-MiR92uc7YpwXZWPxMI1#object-in-context"><code>Object in context</code></a></li><li><code>Filtered selection</code></li></ul></td></tr><tr><td><strong>Filter</strong></td><td><em>Available when</em> <strong>Selection</strong> <em>is Filtered selection.</em><br><br>Define the <a href="/spaces/-MiLU-xcHu0eLZiTxcmZ/pages/-MiR9GGOxcZeghNQPbzV">filter</a> to apply to the data source.</td></tr><tr><td><strong>Values on update</strong></td><td>Set new values for any object class properties in the defined object(s).</td></tr></tbody></table>


---

# Agent Instructions: 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:

```
GET https://docs.appfarm.io/library/action-nodes/update-object.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
