= Operations to update variables value
:description: An operation is an action that updates the value of a variable when a task is executed. You can specify any number of operations per task, they are executed in the order they are listed.

An operation is an action that updates the value of a variable when a task is executed. You can specify any number of operations per task, they are executed in the order they are listed.

== Define operations at task level

An operation at task level updates the value of a variable defined for the task or at process level. You can also use an operation at a task to update the value of a search key.

To define an operation at task level:

. Select the relevant task and go to the *Details* panel, *General* tab, *Operations* pane.
. Click *_Add_* to add an operation.
. From the drop-down list, choose the variable to be updated.
. Launch the Expression Editor, by clicking the crayon icon.
. Using the Expression Editor, enter the expression to define the new value of the variable.
If you define the expression with a script, you can use the current value of the variable being updated in the script, so, for example, you can increment a counter. Make sure that the return type matches the type of the variable being updated.

[WARNING]
====

*Important note*: The scripts used in the operations _at task level_ are designed to be read only scripts. It is therefor not recommended to use them to write data to the database.
Ex: In a human task of a process, you add an operation that instantiates a business object with the result of a script. In the script you create and return the business object, and you also decide to update a document by calling a java API method.
While this call _might_ succeed, such a process design is considered bad practice and its behaviour is not guaranteed across Bonita versions
====

You can define a sequence of operations at a task. The operations are performed in the order in which they are listed, at the end of the task. You cannot re-order operations after they are defined, so you need to define the operations in the order they are to be performed.

== Operation types

=== Business object (BO)

* *_takes value of_* : the value of the right operand variable is used to update the value of the left operand (the BO) using the "=" operator
* _*Java method*_: the left BO is updated with the value from the right operand using an invoked Java method
* _*instantiate with*_: at runtime, when the operator is called, the business data variable points to the selected BO instance if it uses a _Query expression type_. +
 The BO instance must exist in the business data database; otherwise the operator throws an exception. +
 The BO instance is not modified during the operation but from that point onward, any expression or operation in the process can reference this object instance to make changes. +
 If it uses a _Script expression type_, you can use the contract inputs to fill in the BO attributes. +
 Go to xref:define-and-deploy-the-bdm.adoc[Initialize BDM attributes from contract inputs in task operations] for more information.
* *_isDeleted_*: an operator 'Is Deleted' can be called on a business data variable. The BO instance that the business data references is deleted from the database, at runtime, after the task is completed.

WARNING: Calling other operations (including _*instantiate with*_) after calling *_isDeleted_* on the same Business Object, in the same task, is not supported. If you want to re instantiate your Business Object, and perform operations on it, you should do it in a separate task.

WARNING: Operations on business objects can be done only at task level.

=== Simple data and List of options

* _*takes value of*_: the value of the right operand variable is used to update the value of the left operand using the "=" operator

=== Java Object

* _*takes value of*_: the value of the right operand variable is used to update the value of the left operand using the "=" operator
* _*Java method*_: the left object is updated with the value from the right operand using an invoked Java method

=== XML Object

* _*takes value of*_: the value of the right operand variable is used to update the value of the left operand using the "=" operator
* _**XPath update **_: the left object is updated with the value from the right operand using an XPath expression

=== Document

* _*set document*_: the value of the right operand document is used to create a new version of the document
