Save changes later

See also: Fill primary key, Delete later

Event action – Abstract

Purpose: Flags the current reference object for saving when the transaction is completed and fills the primary key if necessary.

images/download/attachments/177911159/image2021-2-4_13-28-52-version-1-modificationdate-1726147535727-api-v2.png

The event action Save changes later flags the current reference object of the event handling for saving.

IMPORTANT◄ While saving, the reference object subject to a scheduled or unscheduled termination of the transaction is actually executed 'later', executing Save changes later on a reference object that has never been saved also has an immediate effect: Analogous to the Fill primary key event action, namely, a value is assigned to the primary key in the id field of the reference object if it is still 0.

Definition of the reference object

In the simplest case, the current reference object is the entity defined by the data context of the event handling.

However, there are also event actions (e.g. Execute with or For each loop) that can temporarily override the current reference object at runtime. The configuration of such event actions provides a defined block for event actions to be executed in the context of the alternative reference object. At runtime, the alternative reference object is considered the current reference object for these event actions, as can be traced via the value of the variable entity, if applicable. Within such an action block, the event action Save changes later also refers exclusively to the entity temporarily defined as the reference object.

Within an event action that provides for an alternative reference object, Resolvers can usually be used to define a specific reference object:

IMPORTANT◄ The action should be performed only with independent entities as reference objects and not, for example, with attributes or positions of business objects. No corresponding check takes place at runtime, and executing the event action for a related object that cannot actually be stored (interactively) on its own may lead to unexpected results when the transaction is completed.

Flag to save

The flag to save takes into account the logon context (company, role, user) applicable at the time of execution of the Save changes later event action, which may be defined at runtime as a temporary alternative from the current session by the Run as event action.

  • If the event action Save changes later is executed multiple times within the same transaction for the same reference object, the flag only takes into account the logon context of the last execution.

  • The determining logon context affects the checking of permissions and – if applicable – the value assignment for entity attributes when saving (see below).

The fact that saving is not directly triggered by executing the event action Save changes later also causes the following effects:

  • If a rollback (by a Abort or a 'real' process exception) is triggered for the same transaction after executing Save changes later, the 'save later' is omitted and any pending changes are lost.

  • The time of execution of the event action for a specific reference object within the same transaction is irrelevant. All changes to the reference object within the transaction are taken into account cumulatively when saving is to be performed.

  • Repeated execution of the event action for the same reference object within the same transaction has no effect, unless different logon contexts are used (see above).

Execute save

The flag to save is taken into account only when the current transaction is completed. If one of the marked reference objects would not be saved by the transaction anyway, an attempt is made to save it explicitly. If this attempt fails because an error message occurs, the transaction as a whole is considered a failure and a rollback is performed. The following aspects must be considered in this regard:

  • The logon context applicable in the course of the flagging (see above) must have sufficient permissions for the reference object ('Change' or 'Create' for new instances).

  • If the system checks content requirements for the entity type of the reference object (required disclosures, uniqueness of characteristics or combinations of characteristics, etc.), the reference object should meet them by the time the transaction is completed.

  • Executing the event action Save changes later in the Try block of a Try/Catch actor does not result in catching errors that occur 'later' (when saving).

IMPORTANT◄ If upon completing the transaction the same entity is flagged to save as well as flagged to delete (see Delete later), the save-flag is disregarded completely.

NOTE◄ Saving objects is generally not supported in the context of Tests for event handlers. However, when the event handler is triggered while running a form in test mode, Save changes later may effectively update or create entities.

Example

A Custom action event 'Save business object' is triggered in the context of various Input forms when a specific business object is to be saved automatically. The data context for the Dispatch custom action event (Form designer) behaviour type can be either the form data (or the entity displayed in the data entry screen) or the data of an embedded form (see Embed forms (Sub-forms)), with the data of an additional entity loaded into the form.

  • As a Triggering event, a specially created Custom action event with the localization 'Save business object' is used.


  • The Validating rule is a Check type on the 'Business transaction object' Type, which is passed by any business objects (shipments, orders, etc.).


REMARKS◄ The Check type here not only ensures that the action cannot be misused to save objects such as user or company accounts. It also prevents, for example, a flag to save being executed for an entity that is completely unsuitable according to its type (e.g. an item of a business object), if corresponding data should be linked by mistake when triggering in a form.


images/download/attachments/177911159/image-2024-9-12_15-29-44-version-1-modificationdate-1726147783744-api-v2.png