Copy instance

See also: Create instance

Value resolver – Abstract

Purpose: Creates a copy of the object present as input value and returns it as return value.


images/download/attachments/62856999/image2022-10-10_17-52-15-version-1-modificationdate-1665417135621-api-v2.png

The Copy instance value resolver creates a copy of the object present as input value and returns it as return value.

If the input value is an entity of a standalone entity type, then copying the instance is equivalent to clicking 'Copy' in an interactive context (see Erfassungsmasken). However, the 'Copy' event (see Common action event) is not triggered.

However, copies of non-independent entity types (e.g., inner entities) can also be created, as the second example below demonstrates.

  • The values of entity attribute properties ('ID', 'Owner', 'Creator', 'Creation date', etc.) are not copied, as in interactive copying.

    • When the transaction to 'Create' the copied entity is completed, these properties are automatically populated.
      IMPORTANT◄ For a copied entity, the Company of session is the 'Owner' (ownerId) by default and not the 'Owner' of the original! This must therefore be explicitly assigned if required (see first example below)

  • Furthermore, as far as applicable in the context of the entity, the following characteristics or relationships of an entity are not copied either:

NOTE◄ The copy created by an entity is volatile, so it must be explicitly persisted when needed, e.g. by pressing 'Save' in an input form or by executing the Save changes later event action in an event handler.

  • In Event handling, a volatile copy of an entity can be flagged for saving at transaction completion using the Execute with and Save changes later event actions. If required, the Fill primary key event action can also be executed in advance to obtain an ID for the entity from the server.

  • A Client workflow can create a volatile copy of an entity, for example, to assign its data to a form element or embedded form via Populate element data. Even then, the volatile entity is persisted only if it is explicitly saved afterwards.

Configuration

The original to be copied is expected as input value.

The value resolver does not use any parameters.

Examples

Simple use case: Duplicating an entity

In the context of a Custom overview (see Custom overviews) a ribbon button is offered for certain entity types to 'duplicate' a single entity selected in the list.

Detail requirements:

  • If the Company of session is not the 'owner' of the selected original, the user should be able to choose whether 'their company' (the Company of session) or the 'owner' of the original should be the 'owner' of the copy.

  • The 'Duplicate', i.e. the copy of the selected entity, should be saved automatically immediately after copying.

  • The selection should remain on the original so that further copies of the original can be made immediately.

Configuration:

IMPORTANT◄ The copy can only be created if the Role of session has the appropriate permissions. Furthermore, the copy can only be assigned a different 'Owner' from the Company of session if this is permitted. This may require the establishment of Company authorizations for all relevant entity types. Alternatively, a Run as event action could be used in the following event handling to temporarily claim a role as Role of session for which ownership restrictions do not apply (e.g., 'Super user'). The configuration shown does not do this.

For 'Duplicate' (DUPLICATE), a Custom action event is added and localized in the relevant dynamic enumeration. The event handling shown on the right refers to this under Triggering events.


The Validating rule uses Check type to ensure that the event was executed in the context of an 'Entity'. Since the 'Entity' class is checked for all entity types, the same event handling can be used for any entities.

Whether Custom overviews support duplication or not for a specific entity type is to be controlled here only by the configuration and assignment of the ribbon macro.


As an Action on passed rule, an Execute with event action is executed:

  • Since data of the original and the copy must be accessed in the action block, the Save entity in variable parameter stores a reference to the original in the original variable.

  • In the Object Resolver parameter, the Copy instance value resolver is used to obtain the – initially volatile – copy of the entity from the input value as an alternative reference object for the event actions in the action block.

  • The action block provides the following operations:

    • Within an If then else event action, first the 'Owner' (ownerId property) of the original entity (in the original variable) is compared with the 'ID' (id) property of the Company of session.

    • Only if there are different owners, the following User callback is executed in the then-branch. The user should confirm (via the 'Yes' button) that the 'Owner' of the original should also apply to the copy or reject this (via the 'No' button). Then no 'Owner' is assigned to the copy, so when it is saved, the Company of session is automatically assigned as the 'Owner'. Details of this event action are shown in the screenshot below

      • There you can see the – statically assigned texts for Title and Text in the query dialog.

      • The Set value event action in the Yes branch of the case distinction defines the non-standard procedure that the 'Owner' of the original should be transferred to the copy.

    • Regardless of whether the User callback is executed and how it is answered, if applicable, the Save changes later event action ensures that the entity created as a copy is saved upon successful completion of the transaction.


images/download/attachments/62856999/image2022-10-10_17-57-26-version-1-modificationdate-1665417446656-api-v2.png

images/download/attachments/62856999/image2022-10-10_17-59-45-version-1-modificationdate-1665417585855-api-v2.png

Use case in client workflow: Duplicate instance of a 'Repeatable entity'

A custom type definition (see Custom type definition) for an 'Aircraft' (Aircraft) entity type contains a 'Loading areas' (areas)property of the 'Repeatable entity' type that lists inner entities of the 'Loading area' (LoadingArea) type. A variety of details can be specified for each loading area.

If an aircraft has several identical or at least similarly specified 'loading areas', it is possible to duplicate an existing definition for a 'loading area' at the push of a button in order to simplify data maintenance. The copy is attached to the existing list in the 'loading areas' (areas) property.

images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/warning.svg CAUTIONimages/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/warning.svg The relationship between an inner entity (here: loading area) and the parent entity (here: 'Aircraft') is established when the parent entity is saved by assigning the id of the parent entity to the parentId property of the inner entity. As an entity attribute, the parentId property is not transferred from the original to the copied instance. Therefore, saving the parent entity after copying an inner entity is essential for the lasting success of the operation. Saving an inner entity through a Save changes later event action, while technically feasible, as long as it points to a valid parentId. However, it is essential to avoid this approach, as it undermines the data sovereignty of the parent entity with respect to its inner entities, which may compromise data integrity and consistency (including with respect to change history).

Runtime example:

Before:

images/download/attachments/62856999/image2022-10-10_18-2-46-version-1-modificationdate-1665417766455-api-v2.png

  • The specifications for a Loading area CENTER/L were created in the Expandable element 'Details' (collapsed in the image).

  • By clicking on the 'Duplicate' Button, another 'Loading area' is added, for which the same 'Details' apply (see image on the right).

NOTE◄ Instead, clicking on the images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/add.svg icon would add a new loading area again (and without details).

After:

images/download/attachments/62856999/image2022-10-10_18-3-28-version-1-modificationdate-1665417808510-api-v2.png

  • The duplicated loading area has already been renamed CENTER/R in the image. The 'Details' collapsed in the image are still identical to the original (CENTER/L).

Configuration:

Clicking the button (see Button) triggers a behaviour of the Client workflow type. On the one hand, it receives the volatile data of the 'Aircraft' entity displayed in the entry form as input value.

Since the button is located in the repeatable element (here: Row layout element) for 'Loading areas', the data of the 'Loading area' instance to be duplicated can additionally be passed per original parameter.

The Client workflow can be configured on this basis as shown on the right:

  • The Validating rule declares via Check type, that an entity of the 'Aircraft' (Aircraft) type is expected as input value.

  • A Modify list event action is configured as the only Action on passed rule.

    • On the left side, the Object property value resolver defines the list to be modified, in this case the list in the 'Loading areas' (areas) property of the aircraft.

    • On the right side, the data of the entry to be added must be provided:

      • A Variable value resolver returns the data of the 'Loading area' to be duplicated, defined as original when it is called via the Client workflow parameter.

      • The concatenated Copy instance value resolver uses this to create a copy that reflects all of the features of the original that can be considered a 'payload'.

images/download/attachments/62856999/image2022-10-10_18-5-15-version-1-modificationdate-1665417916150-api-v2.png