Official Content

In addition to all the automatic controls included by GeneXus in the applications it generates, sometimes users request some specific controls.

In a Transaction object, the rules that must be complied with, or the controls that need to be validated, are defined in the Rules section. 

For instance, if one of the requirements is not to allow storing clients without a name, there's a rule called Error that will prevent that from happening. 

Type “Error”, open brackets and between single quotation marks, enter the text you want to have displayed if the user tries to leave a client's name blank. Close brackets, and now indicate the condition that must be met for that text to be displayed.

The condition is that the CustomerName attribute is empty. Write “if CustomerName”, period:

RulesDefIntellisense

and select: IsEmpty method.

Note: All the stated rules must end with a semicolon.

RulesDefSemicolon

Save and press F5 to see this rule at runtime. 

Run the Customer Transaction object, and if the client's name is left blank, the text that had been defined will be displayed. 

The Error rule doesn’t let you continue if the condition continues to be met, so, the user either enters a client's name or cancels. 

Note that when clicking on the client’s surname, the message stays on screen, because the condition continues to be met.

Enter de Customer name, error rule SAP Fiori Horizon - v18u4

Enter a name and note that now you can continue entering the rest of the client's details.

If there's another requirement that prevents the client’s surname from being left blank, a similar rule needs to be stated. So, copy and paste this rule definition, replace “name” with lastname and change the attribute involved.

Press F5 and run Customer. Leave the client's name empty so that the error associated with a blank name is displayed. Then, enter "Paul" and leave the surname empty; the error message associated with a blank surname is displayed.

There is another rule whose syntax is very similar to that of the Error. It is called Msg rule and the only difference with Error is that if the condition is met, the message is displayed as a notice or warning, but the user can continue working. That is to say, it doesn’t prevent users from moving on, as the Error rule does.

Suppose you want to inform that the client's phone number has been left blank without forcing the user to enter it. To do so, create a Message rule: open brackets, enter the text between single (or double) quotation marks 'The phone is empty', close brackets, and then define the condition for the rule to be executed: “if CustomerPhone”, period, IsEmpty. Don't forget to add a semicolon to complete the rule's definition.

MsgRule

Press F5 to try this functionality.

Note that if the phone number is left blank, and you try to move on, the message that you created is displayed. In this case, it is orange and it lets you continue.

Message rule Customer Transaction V18U4 - SAP Fiori Horizon

This set of rules could be written in any other order, and the result at runtime would be exactly the same because GeneXus decides when each one of the defined rules should be triggered (when the user leaves each involved field, etc.). 

Of course, GeneXus offers more rules to define different kinds of validations and actions. See Transaction rules to know more about this. 

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