# 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](https://docs.appfarm.io/library/action-nodes/while) or [Foreach](https://docs.appfarm.io/library/action-nodes/foreach) 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**.&#x20;
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](https://docs.appfarm.io/reference/platform-concepts/objects#object-in-context). This object in context contains the original values prior to the update and these can be accessed using [data bindings](https://docs.appfarm.io/reference/platform-concepts/data-bindings) and [functions](https://docs.appfarm.io/reference/platform-concepts/functions).&#x20;

In addition, the values set in the update are available as *self-properties.* Self-properties are only available in [functions](https://docs.appfarm.io/reference/platform-concepts/functions). 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="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FPikySso6ULsVgmWkFINH%2Fimage.png?alt=media&#x26;token=74cb1d79-27ad-441c-bd85-3a90ff384621" 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="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FiCY0w2mvWSmHNlboHUqE%2Fimage.png?alt=media&#x26;token=01c59342-de8f-4e77-9f1e-16f139d1ba3b" alt=""><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

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

<div align="left"><figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2F6buCAFkQZsNFIObyJe2k%2Fimage.png?alt=media&#x26;token=43a353e7-ea27-4844-b2f9-05ccf877e7fd" alt=""><figcaption><p>Data binding to the same property, then tick "Value Processor"</p></figcaption></figure></div>

<div align="left"><figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FTDxyJaEneC8eqDDztbEc%2Fimage.png?alt=media&#x26;token=34724d55-7599-42e8-99da-46fea6a60d18" 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="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FVDXUs69c6ThASN71X2SG%2Fimage.png?alt=media&#x26;token=41fdac86-7256-42b8-be24-4bef2a38a522" 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="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FR7uFsi4e5aD0KWh85KBG%2Fimage.png?alt=media&#x26;token=79e945ac-a771-4a21-8fb4-2396b4bb66bb" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2F7KxAzJhc6KUqtTc7Rxgi%2Fimage.png?alt=media&#x26;token=c2af150b-8e5a-4856-acb1-07a15da34026" 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](https://docs.appfarm.io/reference/data-model/object-class-properties), but you want to keep the existing list of references and add (or remove) a set of references. You can use the [Value Processor](https://docs.appfarm.io/reference/platform-concepts/value-processor) for that.

<div align="left"><figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FDq9lsrEJaBRRL4DXbCwH%2Fimage.png?alt=media&#x26;token=260475ca-07f8-4136-833b-2fba2bcca581" alt=""><figcaption><p>Data binding to the same property, then tick "Value Processor"</p></figcaption></figure></div>

<div align="left"><figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FbQpLCdJjLVVLSKh2ZCxV%2Fimage.png?alt=media&#x26;token=337650a8-d658-4d94-9579-f011a5201db4" 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 %}

## 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="../../../reference/platform-concepts/objects#object-selection"><code>Selected object(s)</code></a></li><li><a href="../../../reference/platform-concepts/objects#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="../../reference/platform-concepts/filters">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>
