Store value as variable

Value resolver – Abstract

Purpose: Assigns the input value of the variable addressed via the Variable Name parameter in the execution context.

images/download/attachments/177908237/image-2024-8-13_15-56-24-version-1-modificationdate-1723557384251-api-v2.png

The Store value as variable value resolver assigns the input value to the variable addressed via the optional Variable Name parameter in the execution context.

  • If the Variable Name parameter does not contain any information, then the input value will not be saved.

  • If the addressed variable is already in use in the execution context, it will be overwritten.

  • If the addressed variable does not yet exist in the execution context, it is added.

In each case, the input value is returned unchanged.

In the context of a value resolution chain, any intermediate result can be literally stored 'at random' in order to be able to access it in the further course or to examine the value in the context of Tests.

While in Event handling or in a Client workflow the value of a variable can alternatively be assigned by an event action (e.g. by Set valuee with a Variable value resolver as target), the Store value as variable value resolver e.g. in Association criteria represents the only possibility to store a value directly in the execution context.

Configuration

The optional Variable Name parameter defines by a static text the name for a variable in the execution context to which the input value is assigned as a value.

  • Without any information in the Variable Name parameter, no error will occur. However, the value resolver is then effectively meaningless.

In the example on the right, the Store value as variable value resolver is used within a value resolver chain, which assigns the new company account created via a Create instance value resolver in the input value of the newCompanyAccount variable, whose address field is 'used' in the further course of the chain. The newCompanyAccount variable provides access to the newly created company account in operations performed after accessing the company address in the context of the current value resolution chain.

images/download/attachments/177908237/image-2024-8-13_16-1-32-version-1-modificationdate-1723557692165-api-v2.png

NOTE◄ If the Variable Name is not determined statically in the configuration but rather at runtime, only an assignment via event action (e.g. with the Set value value resolver) can be considered. If the target of the assignment is determined by the Variable value resolver, the name of the variable can be determined via value resolver.

Example

Simple use case: Save intermediate result in a multilevel calculation

Based on numerical values for 'quantity' (quantity), 'unit price' (unitPrice) and an applicable 'tax rate' (taxRate) specified in percent, in addition to the resulting 'grossAmount' (grossAmount), the 'netAmount' (netAmount) should also be calculated as follows:

  • netAmount = quantity * unitPrice

  • grossAmount = netAmount * (1+taxRate/100)

The following configuration demonstrates how the 'net amount' can be stored as an intermediate result in a value assignment for the 'gross amount' via the Store value as variable value resolver.

The subsequent use of the netAmount and grossAmount variables is not discussed here.

Configuration:

Within an event handling that is triggered when a business object is saved, a Set value event action is executed that calculates the 'gross amount' and writes its value as a total result to the grossAmount variable.

  • On the left side of the assignment, a Variable value resolver points to the variable grossAmount as the target of the assignment.

  • On the right side of the assignment, a value resolution chain defines the calculation process and the required intermediate result:

    • The first Calculate value resolver calculates the product of quantity and unit price. The configurations for the quantity and unitPrice variables, which are not expanded in the image, 'read' the corresponding data of the business object at runtime. They apply only within the calculation. The result of the first calculation is the desired intermediate result 'Net amount'. It is written as 'Unit Number' by the concatenated Store value as variable value resolver into the variable netAmount.

    • The second Calculate value resolver calculates the 'gross amount' from the 'net amount', which includes a percentage markup to the 'net amount' defined via the variable taxRate. The formula accesses the input value of the value resolver via the automatically provided input variable. Instead, the netAmount variable could also be addressed for the intermediate result in the given configuration.


images/download/attachments/177908237/image-2024-8-13_16-10-10-version-1-modificationdate-1723558210028-api-v2.png

NOTE◄ The concept demonstrated here can also be applied in a multi-step manner in the same value resolution chain to transfer a series of intermediate results into variables.

More complex use case: 'Validating rule' occupies variables for the 'Actions on passed rule'

In an event handling, the Validating rule determines whether the company to which the logged-in user account (according to User of session) refers as 'owner' (ownerId) owns its company account itself or not.

Actions should only be executed if this is not the case. Among other things, a notification then indicates ownership.

Runtime example:

The 'Username' for the User of session appears in the 'Title' of the notification.

The 'message' below displays, in the context of a text concatenation (including literals to clarify ownership), the name of the 'owner' company of this user account ('Vortex Inc.') and the name of its 'owner' company ('Xflow AG').

images/download/attachments/177908237/image2022-10-4_15-26-14-version-1-modificationdate-1723557295981-api-v2.png

Configuration:


images/download/attachments/177908237/image-2024-9-2_11-40-40-version-1-modificationdate-1725270040362-api-v2.png

The Validating rule of an event handler shown above defines an Entity property rule that compares the 'owner' (ownerId) field for the User of session with the same field in the company account referenced there as 'owner':

  • On the left side of the comparison, the ID of the company that owns the User of session is determined:

    • The value resolver chain starts with the User of session value resolver, which returns the logged in user account.

    • The concatenated Store value as variable value resolver stores this user account in the me variable.
      NOTE◄ The Show alert (Popup) event action in the 'Title' refers to this variable.

    • The concatenated Object property value resolver reads the 'owner' (ownerId) field of the user account that is the User of session.

    • The concatenated Store value as variable value resolver stores the ID of the company account specified as 'owner' in the myOwnerId variable.
      ►NOTE◄ The Variable value resolver at the beginning of the value resolver chain on the right-hand side of the Entity property rule refers to this variable.

  • On the right side of the comparison, the ID of the company that owns the company account that owns the User of session is determined.

    • The value resolver chain starts with the myOwnerId variable, where a lookup is performed for the Class 'Company account' (CompanyAccount) (see Variable value resolver).

    • The concatenated Store value as variable value resolver stores the company account looked up via the Variable value resolver in the myOwner variable.
      ►NOTE◄ The Show alert (Popup) event action in the configuration of the 'Message' refers to this variable.

    • The concatenated Object property value resolver reads the 'owner' (ownerId) field of the user account, the company account that owns the User of session.

    • The concatenated Store value as variable value resolver stores the ID of the company account specified as 'owner' in the myOwnersOwnerId variable.
      ►NOTE◄ The Show alert (Popup) event action in the configuration of the 'Message' refers to this variable.

Since the Validating rule is always processed before any Actions on passed rule are executed, in its context the variables addressed via the Store value as variable value resolver are populated as follows:

Variable

Content

Data type

Use in a Show alert (Popup) event action

me

User of session.

'User'

Read access to the 'username' field in the 'Title'.

myOwnerId

ID of the company account that owns the User of session.

Long

Not used (only within the Validating rule).

myOwner

Data of the company account that owns the User of session.

'Company account'

Read access to the 'name' field of the address (address.name1).

myOwnersOwnerId

ID of the company account that owns the myOwner company account.

Long

Read access to the 'name' field of the address (address.name1) after looking up the relevant company account by ID via the Variable value resolver with Class 'company account'.

images/download/attachments/177908237/image-2024-9-2_15-17-46-version-1-modificationdate-1725283066786-api-v2.png