Default value

Value resolver – Abstract

Purpose: Defines a fallback value that is determined via the value resolvers configured in the Default value parameter exactly when 'no value' ($null) or an equivalent value due to parameterization is present as input value at runtime.

images/download/attachments/113286124/image2022-10-11_18-34-53-version-1-modificationdate-1665506093235-api-v2.png

The Default value resolver defines a fallback value that is determined by default via the value resolvers configured in the Default value parameter exactly when 'no value' ($null) is present as the input value at runtime or an equivalent value based on parameterization. For the runtime behaviour the following cases are differentiated:

Input value at runtime

'On empty string too' option

Return value at runtime

Behaviour

No value ($null)

irrelevant

Default value

The Default value is provided as a fallback value.

Without configuration (default) 'No value' ($null) is returned.

Empty string ('')

images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/check.svg selected

images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/error.svg not selected (default)

Input value

The input value is provided.

Value resolvers for the Default value are not executed.

Any other value

irrelevant

IMPORTANT◄ An empty list ([]) is not considered equivalent to 'No value' ($null).

►NOTE◄ The Default value resolver is used particularly often by means of concatenation after another value resolver, for whose return value it is to provide the fallback value if required. However, this is not obligatory. As usual, the reference object in the context is considered the input value if no concatenated predecessor exists. The Default value resolver can also be used to generate a 'missing' reference object (e.g. via the Create instance value resolver or the List item value resolver).

Configuration

The Default value parameter optionally allows the configuration of one or more concatenated value resolvers that are processed at runtime exactly when the input value is 'no value' ($null).

  • If there is no configuration for the Default value parameter, the return value is 'no value' ($null).
    NOTE◄ However, with $null as a fallback value, the Default value resolver is effectively ineffective if the On empty string too is checked.

IMPORTANT◄ Since a value resolver configuration for the Default value is only relevant at runtime if 'no value' ($null) is present as input value, value resolvers configured for the Default value do not refer to its data type in the context of the configuration. The reference object that may exist in the context of the value resolver also does not automatically apply to value resolvers configured in the Default value parameter. If the Default value is determined on the basis of a reference object, this must be explicitly specified. Typically, a Variable value resolver is used at the beginning of the value resolution chain. The reference object from the context of the value resolver can also be addressed via the entity variable, which is automatically filled by the system.

The On empty string too option is unchecked by default.

If the option (see image on the right) is checked, the configured Default value will be used even if the input value is an empty string.

In the example on the right, an empty string in the input value would be replaced by 'No value' ($null) because no Default value is configured.

images/download/attachments/113286124/image2022-10-11_18-39-19-version-1-modificationdate-1665506359929-api-v2.png

NOTE◄ If at least one value resolver is configured for the Default value, its data type overrides the possibly alternative data type of the input value in the context of the configuration. In specific terms, this means, for example, that the configuration of 'subsequent' value resolvers (e.g. via concatenation) always 'assumes' the Default value as the return value.

The following very simple example illustrates the effect:

In the context of an unspecified text attribute, the Object Resolver parameter in an Execute with event action accesses its 'Text' (textValue) field, whose value is defined as a String. The concatenated Default value resolver should return the Long value 404 as a fallback if no text is returned from the attribute, for example, because it does not exist at all.

At runtime, the returned data type can effectively be both String and Long. For the context of the configuration, however, Long is always assumed in purely formal terms, since this data type is technically at the end of the chain.

If the value resolver chain is extended by a value resolver from the String processing category in the context of the configuration, the reference to the Long data type results in the Substring value resolver, for example, appearing in the 'Unsuitable' category.

In practice, such restrictions can often simply be ignored, provided – as in the example of the Long data type (after an automatic string conversion) in conjunction with the Substring value resolver – the expected results are achieved. However, this is not always guaranteed.

NOTE◄ If the configuration is formally oriented primarily to the data type of the value 'above' the Default value resolver, it may be advantageous to initially dispense with the Default value resolver and only add it when the configuration for the data type expected in the normal case (input value is not $null) has been completed. In any case, Tests should finally be performed to ensure that even a Default value with an alternative data type is processed without any problems and with the expected results.

images/download/attachments/113286124/image2022-10-11_18-37-27-version-1-modificationdate-1665506247671-api-v2.png

Examples

Simple use case: Remove empty text field of an entity from XML

The input form for Roles offers, among other things, a Text field element for editing the 'Role description' (roleDescription) field, in which an informative description for the role can optionally be stored.

If the server-side saved state of a role already contains a 'Role description' and all text characters are removed in the input form, an 'empty string' is assigned to the role description when the role is saved.

This leaves an empty roleDescription element in the XML format:

XML export (shortened) of a role with 'emptied' role description
<?xml version="1.0" encoding="UTF-8"?>
<base:Role ... active="true">
<roleName>myRole</roleName>
<roleDescription></roleDescription>
<parentRole>1001</parentRole>
...
</base:Role>

The user cannot use the input form to make the roleDescription element disappear completely after the entity field has been saved once.

On the other hand, in an event handler that is executed when a role is 'changed', the 'Role description' (roleDescription ) field can be automatically assigned 'No value' ($null) to clear the field completely.

Configuration:

The event handling shown on the right reacts to the 'Change' event (see Common action event) as the Triggering event.


The Validating rule uses Typprüfung to ensure that the following event actions are executed only in the context of a 'Role'.


The only Action on passed rule is a Set value event action:

  • The left side defines the 'Role description' (roleDescription) field as the target of the assignment.

  • The right side accesses this field in read-only mode via the Object property value resolver. The concatenated Default value resolver should become active exactly if the field contains an empty string. Then the Default value 'No value' ($null) is assigned so that the field is deleted and also 'disappears' from the XML.

    • The On empty string too option has been checked to ensure the desired replacement in case the user has emptied the 'Role description' in the input form.

    • If the 'Role description' field does not yet exist because it has never been filled, the input value ($null) is replaced by the default value ($null). The assignment is then 'value neutral'.

    • Any other value for the 'Role description' other than $null will be assigned to this field unchanged. This makes the assignment 'value neutral' as well.

images/download/attachments/113286124/image2022-10-11_18-41-32-version-1-modificationdate-1665506492102-api-v2.png

Typical use case: Define a fallback value for the source value in the context of an assignment

Within a shipment (see Shipments) the 'Invoice address' (more precisely: the address in a 'Company and address attribute' for the Company type 'Bill to party'/INV) should be initialized automatically with an existing address specification for another company type.

There are two types of companies that can be considered as the source for the pre-assignment:

  1. Company type 'Principal' (AAL)
    or – if no address for the 'Principal' is given –

  2. Company type 'Delivery party' (DDA)

Configuration:

The desired priority rule when initializing the 'Billing address' can be solved clearly with the Default value resolver:

To prepare, two Set value event actions transfer the addresses from the two company and attributes into variables that are candidates for initialization. This is not technically necessary, but it allows a clearer display and simplifies access to the fallback value in the Default value resolver, for which the shipment is not automatically available as a reference object (see note in the 'Configuration' section).

The internal name for the respective Company type (AAL, DDA) is used as the variable name.

NOTE◄ If no address is specified for the respective Company type, the variable is assigned 'no value' ($null).

The third Set value event action can operate on the two variables to define the actual value assignment for the 'Billing address' (on the left side of the assignment). On the right side of the assignment, two value resolvers are concatenated for this purpose:

  • The first Variable value resolver first accesses the higher priority source value from the variable AAL.

  • The concatenated Default value resolver returns the AAL address from the input value if it exists (i.e. is not $null). If no AAL address is available, the DDA address is used as a 'substitute'. If this does not exist either, no address is assigned (or any existing assignment is deleted).

images/download/attachments/113286124/image2022-10-11_18-43-4-version-1-modificationdate-1665506584628-api-v2.png

More complex use case: Cascading testing of multiple fallback values

Sometimes several sources come into question for a value assignment, which are checked step by step as a cascade of fallback values until a value is found.

In a specific use case, the User of session is addressed in a notification about the first filled field from the following list:

  • 'Name 3' from the address (address.name3) ... or if not filled in ...

  • 'Name 2' from the address (address.name2) ... or if not filled in ...

  • 'Name 1' from the address (address.name1) ... or if not filled in ...

  • 'Username' (username)

NOTE◄ Since the 'Username' for a user account must always be filled in, this field is the ideal completion for the fallback cascade.

Runtime example:

Username

Name 1

Name 2

Name 3

Effective salutation

anne

Anne

<empty>

<empty>

Anne

abusch

Anne

Busch

<empty>

Busch

ahbusch

Anne

Helga

Busch

Busch

import

<empty>

<empty>

<empty>

import

Configuration:

In the configuration, a fallback cascade can be achieved using two different methods:

In both cases, it must be taken into account that the reference object (here: the user account identified as the User of session) must be addressed again in each instance of the Default value resolver in order to access its fields in the Default value parameter.

Solution option 1: Concatenating several instances of the Default value resolver

The configuration shown on the right shows how the 'fallback cascade' can be mapped by concatenating instances of the default value resolver:

  • The User of session value resolver, in conjunction with the Input object (type safe) value resolver, returns the currently logged in user account.

  • Per Store value as variable, this user account is stored in the USER variable to simplify repeated access by the various instances of the Default value resolver.

  • The concatenated Object property value resolver accesses the address.name3 field, which has the highest priority for consideration as a salutation.

  • The following concatenated instances of the Default value resolver access further source field candidates according to the required hierarchy, if necessary, because there is no available input value yet.

    The user account stored in the USER variable must first be set as the reference object in the Default value parameter.

    NOTE If the user account were given as a reference object (e.g. within an Execute with event action), the Store value as variable value resolver could be omitted if the entity variable, which is automatically filled by the system, is specified in the Default value instead of the USER variable.

images/download/attachments/113286124/image2019-4-8_11-10-51-version-1-modificationdate-1665482363809-api-v2.png

Solution option 2: Nesting of several instances of the Default value resolver.

The concatenation of the Default value resolvers shown above results in all three instances of the value resolver always being run through 'serially' at runtime, even if a value has already been found for the salutation. The Default value is only 'resolved' in each case as long as no value has yet been found for the salutation. But the chain must be worked off purely in a technical way step by step up to the last value resolver, although the final result is already fixed.

In the alternative configuration shown on the right, nesting the instances of the Default value resolver ensures that the fallback cascade only needs to be run until a result is obtained:

  • The configuration is identical to the above example up to the first instance of the Default value resolver.

  • The second instance of the Default value resolver, on the other hand, is now not appended at the end of the entire concatenation, but is appended to the value resolver chain in the Default value parameter of the first instance. At this position the instance is processed only if the address.name3 field does not contain a value.

  • The value resolver chain in the Default value of the second instance is executed only if address.name2 does not contain a value either. Only then is the third instance of the Default value resolver contained therein processed at all, to check whether the access to address.name1 returns a return value.

  • The value resolver chain in the Default value of the third instance is executed only if none of the previously checked fields contains a value. Then the user name (username) is assigned as a salutation, which by definition must be filled in for each user account.

images/download/attachments/113286124/image2019-4-8_11-15-46-version-1-modificationdate-1665482363819-api-v2.png

NOTE◄ Even if the nested use of the Default value resolver in solution option 2 represents the logically more consistent configuration and theoretically promises a minimal performance advantage with an increasing number of 'escalation levels', solution option 1 appears to be significantly more transparent and more 'readable' for a cascade of only three levels. It is also easier to maintain if the order of the steps in the cascade needs to be adjusted later.