Monday, 26 February 2024

How to use Side Effects in RAP (Restful Application Programming) Model

Introduction


When a user modifies the content of a field, and it affects the other fields in the UI. This is known as a side effect.

Side Effects annotations indicate which targets are to be refreshed in order to display updated values. These field values change due to the change of a field, action, or decision action. There are various ways to annotate side effects by combining the triggers and the affected components.

Advantage of Side Effects


When a user modifies the data of draft instance on UI, it is not necessary that all the fields will trigger a READ request. This could result in inconsistent data display on the draft instance. This situation can be overcome by the use of side effects.

Types of Side Effects


The following RAP BO attributes have side effects that can be defined in the base behavior definition:

◉ Field: The defined targets are reloaded and the side effect is initiated whenever a defined field is modified on the user interface.

Example:


          - side effects { field MyField affects field Targets, messages; }


          - side effects { field MyField affects entity Targets, messages; }


          - side effects { field MyField affects $self, messages; }

◉ Action: The defined targets are reloaded, and the side effect is triggered whenever a defined field is modified on the user interface.

Example:

          - side effects { action MyAction affects field Targets, messages; }


          - side effects { action MyAction affects entity Targets, messages; }


          - side effects { action MyAction affects  $self, messages;}

◉ Determine Action: The define targets are refreshed and the determine action is triggered whenever the defined source is modified.

Example:

- side effects { determine action MyDetermineAction executed on sources affects Targets, messages; }

Example of adding number of days to current date


When the user changes the value of InputDays, the determination CalculateDate is called and modifies the values of OutputDate by adding InputDays in CurrentDate. In order to show the updated values without a refresh, side effects is required.

Step 1 - Add a statement to your behavior definition in which you indicate which RAP BO fields are affected by other fields.

Code Snippet for Behavior Definition –

side effects
  {   
    field InputDays affects field OutputDate;
  }

  determination CalculateDate on modify {  field InputDays; }

Step 2 - Add 'use side effects' in the behavior projection to enable the side effects.

Code Snippet for Behavior Projection –

projection;
strict ( 2 );
use draft;
use side effects;

define behavior for ZC_Calculate_Date alias CalculateDate
use etag

{
  use create;
  use update;
  use delete;

  use action Edit;
  use action Activate;
  use action Discard;
  use action Prepare;
  use action Resume;
}

Output


During User Input -

How to use Side Effects in RAP (Restful Application Programming) Model
Output

No comments:

Post a Comment