Official Content

Groups GeneXus code that's executed sequentially up to the last line, unless there is an error that interrupts it.

Syntax

Event 'ClientEventName' | Control.AssociatedControlEvent
   Composite
      Event_code
   EndComposite
EndEvent

Where:

ClientEventName
     Is the user event name.

Control
     Is the control name that you program the event AssociatedControlEvent

AssociatedControlEvent
     Is one of the events associated with controls (such as tap, long tap, drag, drop, PageChanged, ControlValueChanged, etc. -depending on the control type-)

Event_code
    It details the code to be executed when the event occurs.  At least two commands are needed.

Description

The code block Composite/EndComposite groups GeneXus code. This code is executed sequentially to the last line, except when an error in any of such lines occurs. In this case, the sequence will be interrupted.

Therefore, its two main premises are:

  1. If one of the instructions (calls or assignments) fails, the rest are not executed.
  2. Error messages (automatic ones as well as loaded by the developer) are displayed on the device screen. 

The use of this command is not a must when two or more invocations are performed on an event. Instead, error handling can be done through the &Err and &ErrMsg variables.  

The &Err variable takes on a value greater than 0 when an error occurs, while it is set to 0 if the operation runs smoothly.

The possible values of &Err are used to identify the nature of the error:

  • 1 for a generic error,
  • 2 if the user cancels the action,
  • 3 for incorrect parameters.

When an event invokes a GeneXus object located on the server side, such as a Procedure object or a Data Provider object, the value of &Err will reflect the HTTP code returned by that call in case of error. For example, HTTP 404 or 500. 

In situations where no response is received from the server (no HTTP code), &Err will be set to 1. 

The &ErrMsg variable contains the description of the error that would be displayed on screen if it were inside a Composite block.

It is important to note that in the case without Composite, an error message is not automatically displayed to the end user, and it is your responsibility to manage how these errors are handled and communicated to the end user.

Sample

Sample with the composite command

Event 'UpdateEmail'
  Composite 
    UpdateEMail.Call(ClientId,&ClientEmail) 
    Interop.SendMessage("Your Email has been updated successfully in my database", ClientMobilePhone) 
  EndComposite
EndEvent

Sample without the composite command

Event 'UpdateEmail'
   UpdateEMail.Call(ClientId,&ClientEmail) 
   If &Err <> 0 
      msg(&ErrMsg) 
   Else 
      Interop.SendMessage ("Your Email has been updated successfully in my database", ClientMobilePhone) 
   EndIf
EndEvent

See Also

Composite examples

Videos

Start Video Grammar of Events on the Client Side and Composite Command
Start Video Events in Mobile Applications

  

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant