OutSystems Agile Platform 5.0 - Form Validations
OutSystems Agile Platform 5.0 - Form Validations
OutSystems Agile Platform 5.0 - Form Validations
The Agile Platform is the first fully integrated platform for the delivery and management
of web business applications using agile methodologies. Download and install the free
version of the Agile Platform, and start developing your web business applications today!
http://www.outsystems.com/Download
Learn Ad-Hoc
After installing the Agile Platform, Service Studio opens showing several tutorials you can
follow to learn how to use the Agile Platform. Simple sample applications are also available
to get started!
http://www.outsystems.com/GettingStarted
Ask OutSystems
Ask directly to OutSystems. Let us answer your questions, and give us your feedback. We want to hear from you!
http://www.outsystems.com/AskOutSystems
In this exercise you will learn how to bullet proof your application by applying a series of rules to
validate the user inputs, and elegantly handle unexpected errors (well... as elegant as an error can
be).
Take a minute to understand how all this is organized. Each exercise has 3 levels:
1.1 Tasks each task is comprised of a goal (its purpose) and a sequence of steps
a) Steps Individual activities you must undertake to achieve your goal and complete your task
Instructions These are detailed descriptions of how to perform each step. They will vary in detail
depending on the expected familiarity with the given task.
During the course of the exercise, you can The closer look boxes (like this one) provide you
decide the level of assistance you want. tips and additional information regarding a step.
Skip the instructions if youre looking for a They may also contain links (in blue) to online
challenge and come back to them if you resources, namely the Agile Platform documentation,
get stuck. where you can find more detailed information about
some of the concepts and tools under discussion. Dont
forget to check them out!
Note: With each hands-on exercise comes a baseline application, we recommend you use your own
application (the one that was the output of the previous hands-on exercises) instead, but if you prefer, you can
always use the baseline application provided with this exercise and proceed with the hands-on.
You can learn more about the Edit Records runtime properties here.
e) If the outbound connector of your If element is the False path, swap the If element connectors.
Notice the label of the If element outbound connector. If its False this means your
CreateOrUpdateCONTACT action is on the False path and you want it to be on the True path. Right-click
the If element and select Swap Connectors.
f) Add an End element and connect the If element to the End element.
Drag the End element from the tree on the left of your
screen and drop it somewhere to the right of the If When the flow of a Screen Action
element. Connect the two together by dragging from the If ends in a End element, this means that
element to the End element when the cursor turns into a if the flow reaches this point, you want
cross. to immediately return to the screen.
Goal: Add the logic to check if the email is valid (lets assume an email is
valid if it has a @). If not, return an appropriate validation message.
a) Rearrange the flow to get some free space before the If element.
Youll be adding some logic between the Start element and the If element.
Rearrange your flow by dragging the elements (remember that you can select
and drag more than one element at a time) in such a way that you get some
free space between them.
b) Add an If element to the action flow immediately after the Start
element and set its label to Invalid Email?.
Drag an If element from the left-hand tree until it is over the arrow and drop it
only when the arrow turns blue. Change the Label property in the bottom-right
of the screen to Invalid Email?.
c) Add the If element condition that checks if the text in the input widget is a valid email.
Open the Expression Editor for the If element
Condition property by double-clicking the If
element in the action flow. Expand Built-in
Functions > Text and double-click the Index
function. Place the cursor in the first
argument. Expand Widgets > EditRecord1 >
Record > CONTACT and double-click the
Email attribute. Place the cursor in the
second argument and type @ (enclosed in
quotes because its a text literal). Type = -1
after the function call. Press OK to close the
Expression Editor.
This was the first time we used one of the Built-in Functions the Agile Platform provides you. You
have a lot more, spread through several folders and they may be used in any expression.
If you have any question regarding the behaviour of a specific function you can simply select it in the
scope tree and a short help text is displayed on the right.
In our case we used the Index function to determine if the search text @ existed anyware in the
Email the user typed. This function returns -1 if the search text isnt found.
d) Add an Assign element to the action flow and set its label as Invalid Message. Connect the If
element to the Assign element and the Assign to the Valid? If.
Drag the Assign element from the left-hand tree and drop it in the empty space to the right of the Invalid
Email? If element. Change the Label property in the bottom-right to Invalid Message. Connect the
Invalid Email? If element to the Assign element by dragging between them when the cursor turns into a
cross and then connect the Assign element to the Valid? If element.
e) Set the assignments to mark the widget as not valid and an appropriate validation message.
Select the Assign element by clicking it in the action flow. Double-click
the Variable 1 assignment label (in the Properties box on the bottom-
right of your screen) to launch the Select Variable window. This
window displays all variables available on scope.
Expand Widgets > EditRecord1 > Widgets >
CONTACT_Email and pick Valid (through
double-click). In Expression 1 type False.
Notice that a new slot for a new assignment
was added in the Properties Box. Double-click the Variable 2 assignment label to
launch the Select Variable window. Expand Widgets > EditRecord1 > Widgets >
CONTACT_Email and pick ValidationMessage. In Expression 2 type Not a valid
email address. (enclosed in quotes because its a text literal).
You can learn all the details on validating end-user typed values in the online help.
a) Verify your eSpace. Fix any errors or warnings you may have.
Press the Verify button in the Toolbar. If you have any errors or warnings, they will be displayed in the
TrueChangeTM window. Fix them until you have a valid eSpace.
You can double-click the Error and Warning messages and be redirected to the location where
the error was detected. The element/property that originated the message will also have the focus.
Goal: Add an additional validation rule to prevent the creation of contacts with an existing email.
We wont provide you the steps to complete this task. We want you
to try it for yourself, without assistance.
Challenge
Remember to test this validation for both the create and
update function. The update function has an extra twist because if
you didnt changed the email, the database already as a record with
that email the one youre editing.
2. Handling Exceptions
The variable will store the error message (if any). This way is pretty straightforward to
determine if we have an error: If we do, the variable is not an empty text; if we dont, the variable
wont be empty.
Goal: Catch any Database Exception that may occur in the Delete
screen action of the Category_Show screen. Construct an elegant
error message to be displayed.
a) Open the Category_Show Delete Action.
Double-click the Category_Show Delete Action in the eSpace Tree on
the right (under Screen Flows > Main Flow > Category_Show).
b) Drag an Error Handler element and drop it somewhere to the
right of the existing flow. Set the exception to Database.
Drag an Error Handler element from the left-hand tree and drop it in
the empty space to the right of the existing flow. Pick Database from
the Select Exception window.
When an Exception is raised, the current execution flow is aborted and the flow restarts in the
Error Handler element that handles that exception. This new flow is called the Exception Flow. When
you set the Exception to Database youre stating that only exceptions originated from the database
will be handled (and we are looking for a referential integrity violation).
You can learn more about Types of Exception on the Online Help.
c) Add an Assign element to the Exception Flow and set its label to ErrorMessage. Connect the
Error Handler element to the Assign element.
Drag the Assign element from the left-hand tree and drop it in the empty space below the Error Handler
element and name it ErrorMessage. Connect the Error Handler element to the Assign element by
dragging between them when the cursor turns into a cross.
d) Assign to the ErrorMessage local variable a custom message to alert for the probable referential
integrity issue followed by the system
exception message.
Select the Assign element by clicking it in
the action flow. Double-click the
Variable 1 assignment label (in the
properties box on the bottom-right of
your screen) to launch the Select
Variable window that displays all
variables available on scope. Pick the
ErrorMessage local variable (through
double-click). Double-click the Expression
1 label to launch the Expression Editor.
Type in the expression as depicted.
Notice how the + operator is used
to concatenate text. Notice that after
you type in Session. the expression The Session variable ExceptionMessage stores the
editor autocomplete appears. message of the last exception raised.
e) Add an End element to the Exception Flow and connect the Assign element to the End
element.
Drag the End element from the tree on the left-hand and drop it in the empty space bellow the Assign
element. Connect the two together by dragging from the Assign element to the End element when the
cursor turns into a cross.
a) Verify your eSpace. Fix any errors or warnings you may have.
Press the Verify button in the Toolbar. If you have any errors or warnings, they will be displayed in the
TrueChangeTM window. Fix them until you have a valid eSpace.
b) 1-Click Publish your eSpace.
Publish the eSpace by pressing the 1-Click Publish button in the Toolbar or by using the F5 key.
c) Test the features youve just implemented.
Press the Open in Browser button which will open the MyContacts application in your browser.
To test this feature, simply try to delete a category in use (a category that is assigned to at least
one contact). In this scenario the database referential integrity validations cause an exception and
the exception handling logic is called.
Wow! What an ugly error message coming from the database! To make this feedback prettier, go
back and revise the expression of the ErrorMessage local variable. Try not appending the session
variable ExceptionMessage
d) Congratulations!
Now take the challenge ahead and protect all your screens. To advance and learn more, continue your
Online Training, or follow the next tutorial Reuse Pages and Logic.
Goal: Add an exception handling pattern (similar to the one you just did) to the Import action of the
Contact_Import screen (handle All Exceptions) that will detect
invalid file formats and display an appropriate message.
We wont provide you the steps to complete this task. We want you Challenge
to try it for yourself, without assistance.
To test this feature try to import a file which isnt an excel file (use a word document or a simple
text file). If you want to know even more about exception handling, check this out.
http://www.outsystems.com/Academy
http://www.outsystems.com/TechCenter
Moving on
Thank you for completing this hands-on exercise! Its now time to move on to the next lesson But
before that, leave us your suggestions and questions.
Submit Feedback
To leave us your suggestions and feedback, either regarding
this training material or not. We want to hear you!
Ask OutSystems
To ask help directly to OutSystems. We are here to answer
any question, may it be technical or not!
http://www.outsystems.com/AskOutSystems