Defining Logic Exercise
Defining Logic Exercise
Defining Logic Exercise
Table of Contents
Outline................................................................................................................................. 2
Resources 2
Scenario 2
How-To................................................................................................................................. 4
Getting Started 4
Negative Or Positive? 7
Order of Magnitude 13
Factorial 16
[email protected] © 2020 by OutSystems. All rights reserved. OutSystems is a registered trademark of OutSystems. The information contained
herein is subject to change without notice. All terms and conditions for OutSystems products and services are set forth in the
www.outsystems.com agreements accompanying such products and services. Nothing herein should be construed as constituting an additional
warranty. OutSystems shall not be liable for technical or editorial errors or omissions contained herein.
Outline
In this exercise, we will focus on developing some logic flows using an If, a Switch, and
an implementation of an ad-hoc loop. These tools will be used to help us on the
following scenarios:
When this is completed, the application will have three Actions that will support all of
these scenarios.
Resources
This exercise has a Quickstart application already created. This application has
everything needed to start the exercise. This quickstart application can be found in the
Resources folder of this exercise, with the name Logic Exercise.oap .
Scenario
In this exercise, we will start from an existing application with one module. Inside that
module we have one screen, called Home .
www.outsystems.com • [email protected] 2
The screen has three sections with a set of Buttons: Negative or Positive? , Order of
Magnitude , and Factorial .
Each of these sections is related with the Screen Actions of the Home screen, with the
same name. Specifically, each one of the Screen Actions is called when a button of the
section of the screen with the same name is clicked.
www.outsystems.com • [email protected] 3
How-To
In this section, we will show you how to do this exercise, with a thorough step-by-step
description. If you already finished the exercise on your own, great! You don't need
to do it again. If you didn't finish the exercise, that's fine! We are here to help you.
Getting Started
First, we need to install the Quickstart file, which has an application ready for the
exercise. This application has one screen containing a set of buttons. These buttons are
bound to three screen actions that you will implement in the course of the exercise.
www.outsystems.com • [email protected] 4
The first step that we need to take is to install the Quickstart application in our
development environment. Before proceeding, you must have Service Studio opened
and connected to an OutSystems Environment (e.g. Personal Environment).
1) In the main window of Service Studio, select the Environment menu on the top
left.
3) In the new dialog that appears, change the file type to OutSystems Application
Pack (.oap), find the location of the Quickstart and open the file named Logic
Exercise.oap
www.outsystems.com • [email protected] 5
4) In the new confirmation dialog, select Proceed
5) The application will begin installing automatically. When it's finished, we're
ready to start!
www.outsystems.com • [email protected] 6
7) The application has only one module. Let's open it!
Negative Or Positive?
In this section, we will implement the first of three screen actions. This one will validate
if a number is positive, negative or zero.
1) The module already has the Home Screen created, with three Screen Actions.
www.outsystems.com • [email protected] 7
2) The Screen has a set of four buttons that call the NegativeOrPositive Screen
Action. Each one of these buttons is associated to that screen action with a
different value for the Number Input Parameter.
Number < 0
www.outsystems.com • [email protected] 8
7) Drag a Message to the right of the If
"Negative Number."
10) Drag an End and drop it to the right of the Message, then create the connector
between both.
www.outsystems.com • [email protected] 9
11) Drag another Message , and drop it on the False branch of the If.
"Positive Number."
13) Publish the module, and test the four buttons inside the Negative or Positive?
area.
14) Open the application in the browser to validate that each button shows the
correct info message.
15) Notice that when the button with 0 is pressed, the Positive Number feedback
message is shown.
www.outsystems.com • [email protected] 10
16) Drag another If and drop it between the If and the existing If.
Number = 0
18) Drag another Message and drop it to the right of the newly created If, then
create the True branch connector from the If to the Message.
www.outsystems.com • [email protected] 11
20) Drag an End node and drop it to the right of the newly created Message, then
connect both. The flow should look like this
21) Publish the module and test again the existing buttons inside the Negative or
Positive? area.
www.outsystems.com • [email protected] 12
Order of Magnitude
In this section, we will implement another Screen Action. This one will analyze a given
number and return either one of the following options: "<1K", "<10K", "<100K" or
">=100K".
2) Drag a Switch node and drop it between the Start and End.
www.outsystems.com • [email protected] 13
3) Drag a Message and drop it to the right of the Switch
4) Set the Message property of the recently added element to "<1K" , then create
a connector from the Switch to the Message.
8) Create another connector from the Switch to this new Message, then set the
Condition of the connector to
www.outsystems.com • [email protected] 14
9) Repeat the previous three steps to make your logic look like the following
10) Drag one End node and drop it to the right of the flow, then connect the three
existing Messages to that End node.
www.outsystems.com • [email protected] 15
12) Set the properties of the newly created Message as follows
15) Click the Open in Browser button and test the five existing buttons on the
Order of Magnitude area.
Factorial
In this section, we will implement the final Screen Action logic that will calculate the
factorial of a number.
4! = 4 x 3 x 2 x 1 = 24
7! = 7 x 6 x 5 x 4 x 3 x 2 x 1 = 5040
www.outsystems.com • [email protected] 16
More information about the factorial function can be found in
https://en.wikipedia.org/wiki/Factorial
1) Switch to the Logic tab, right-click the Server Actions folder, then select Add
Server Action.
3) Right-click the CalcFactorial Server Action and select Add Input Parameter
4) Set the Name of the Input Parameter to N , and make sure the Data Type is set
to Integer .
www.outsystems.com • [email protected] 17
5) Right-click the CalcFactorial and select Add Output Parameter
6) Set the Name of the Output Parameter to Result , make sure the Data Type is
set to Integer , and the Default Value is 1 .
N > 1
www.outsystems.com • [email protected] 18
9) Drag an Assign and drop it to the right of the If
www.outsystems.com • [email protected] 19
12) Right-click the Exceptions Folder and select Add User Exception
14) Drag another If and drop it between the Start and the existing one
N < 0
www.outsystems.com • [email protected] 20
16) Drag the previously created Exception and drop it to the right of the If created
above
17) Create the True branch connector from the If to the Raise Exception element.
18) Select the Raise Exception element, and in its properties set the Exception
Message to "Number must be positive." .
19) Return to the Interface tab, and open the Factorial Screen Action
www.outsystems.com • [email protected] 21
20) Drag a Run Server Action from the toolbox and drop it between the Start and
End.
21) In the dialog, select the CalcFactorial Server Action that we created and
implemented in previous steps, then click OK.
www.outsystems.com • [email protected] 22
22) In the properties, set the N argument to the Number input parameter.
23) Drag a Message and drop it between the Run Server Action and the End
26) Publish the module, then click the Open in Browser button to test the
application.
27) Below you can find the expected results for each number
www.outsystems.com • [email protected] 23
1! = 1
3! = 6
8! = 40320
-5! = (Invalid Number Exception)
www.outsystems.com • [email protected] 24