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.
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:
Working state (current working state, working state history)
Tracking state (current tracking state attributes, tracking state history)
Assignment of Tags
Assignment of Association criteria
►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:
|
|
|
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.
CAUTION
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:
►NOTE◄ Instead, clicking on the |
After:
|
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:
|
|