GeneXus for SAP Systems First Rules definitions

Official Content

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

In transactions, the rules that must be complied with, or the controls that we are asked to validate, are defined in the Rules section. 

If, for example, a requirement is not to allow storing of clients without a name... we have a rule called Error that will enable us to avoid that.

We type “Error”, open brackets and between single quotation marks we enter the text we want to have displayed in the event that the user tries to leave a client name blank... we close brackets... and now we only have to indicate the condition that must be met for the text to be displayed.

The condition is that the CustomerName attribute is empty… so we write “if CustomerName”, period, 

RulesDefIntellisense

and here we select: IsEmpty.

All the rules we state must end with a semicolon, so we include it.

RulesDefSemicolon

We save... and press F5 to see this rule at runtime. 

We run the Customer transaction, and if we leave the client name blank and leave the field,

RulesRuntime

the text we defined is displayed.

The Error rule doesn’t allow us to move on if the condition continues to be met… so, the user either enters a client name to be able to continue or cancels. 

Note that if we try to click on the client’ surname, the message stays on screen because the condition continues to be met.

We enter a name... and see that we can continue entering the rest of the client's details.

If another requirement involved preventing the client’s surname from being left blank, a similar rule would also have to be stated. So, we copy and paste this rule definition... replace “name” with lastname and change the attribute involved:

ErrorRules

We press F5... run Customer... and leave the client's name empty... the error associated with a blank name is displayed... we enter Paul... and try to leave the surname empty.... the error associated with a blank surname is displayed.

RulesRuntime2

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

If, for example, we want to inform that the client's phone number has been left blank without forcing the user to enter it, we can create a Message rule, open brackets, enter the text between single (or double) quotation marks... 'The phone is empty'

we close brackets... and next we define the condition for the rule to be executed: “if CustomerPhone” … period… IsEmpty. And we type a semicolon to complete the rule definition.

MsgRule

We press F5 to try this functionality...

Note that if we leave the phone blank and try to leave the field,

MsgRuleRuntime

the message that we created is displayed. In this case it is orange and we can move on.

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 available rules to define different kind of validations and actions. 

Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.