Building Functions with Low-Code
Last Updated 3/03/2022
Create a Function Using Five's Low-Code Editor
Five's Low-Code Editor is designed for someone who has little or no-coding experience as once you have connected the blocks together, Five will generate the syntactically correct JavaScript from the blocks. Your application can then use this code to add functionality such as performing calculations or verifying correct data. You drag the blocks from the library onto the editor and connect these together.
Below is a short video to demonstarte how to use Five's Low-Code editor before you begin to use it.
Build a Function
Requirement
The Developer or Control role is required to create, read, update, and delete a function.
The CalculateTotal function has been coded so that if attached to the Buys form it will multiply the Quantity and Price fields together and then add the value in the Fees field. This same function will also be attached to the Sells form where it will execute the same equation, however, it will minus the value in the Fees field.
Select [ Functions ] in the [ menu ].
Click the [ Add Item button ] in the [ list app bar ].
Type " CalculateTotal " in the [ Function ID field ].
Click the [ lookup icon ] in the [ Language field ] and select " Low-code ".
Click in the [ Code field ] to open Five's [ Low-Code editor ].
- Select [ Logic ] in the [ toolbar ].
Click, hold, and drag the [ if/do block ] into the [ workspace ].
Click the [ cog ] in the [ if/do block ].
Click, hold, and drag the [ else block ] and connect with the [ if block ] in the [ popup window ].
Click the [ cog ] to remove the [ popup window ].
info
else if
blocks are conditional statements that are commands for handling decisions and returning a boolean value.
- The
if
statement specifies a block of code to be executed if a condition istrue
. - The
else
statement specifies a block of code to be executed if the condition isfalse
. - The
else if
statement specifies a new condition if the first condition isfalse
.
- Select [ Logic ] in the [ toolbar ].
- Click, hold, and drag a [ Comparison block ] and connect with the [ if/do/else block ] in the
if
position.
info
Comparison Operators
A comparison block takes two inputs and compares them. There are six comparison blocks.
= equals
≠not equals
< less than
≤ less than and equals to
> greater than
≥ greater than and equals to
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Current Form block ] and connect in the first input position of the [ Comparison block ].
Select [ Values ] in the [ toolbar ].
Click, hold, and drag the [ Quote block ] and connect in the second input positon of the [ Comparison block ].
Type " Buys " in the [ Quote block ].
warning
When typing values in such as Buys
, it needs to exactly the same as the ID you are referencing otherwise your function will not work. It is case sensitive.
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Set Form block ] and connect with the [ if/do/else block ] in the
do
position.Click the [ lookup icon ] in the first [ field ] and select " Buys ".
Click the [ lookup icon ] in the second [ field ] and select " Total ".
info
The Set Form block allows you to select the field on the form that will hold the returned value if the condition is true
. The block has two lookup lists, the first lookup list will hold all the forms in your application and the second lookup list will hold all the fields for the selected form.
Select [ Math ] in the [ toolbar ].
Click, hold, and drag the [ Equation block ] and connect with the [ Set Form block ].
Select [ Math ] in the [ toolbar ].
Click, hold, and drag the [ Equation block ] and connect in the first input position in the [ Equation block ].
warning
Ensure the second equation block is in the first input position for Five to correctly apply Parentheses.
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Form block ] to the first input position in the [ Equation block ].
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Form block ] to the second input position in the [ Equation block ].
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Form block ] to the third input position in the [ Equation block ].
info
The Form block allows you to select the fields on the current form that hold the values needed to perform the calculation.
Click the [ lookup icon ] in the first [ field ] on the first [ Form block ] and select " Buys ".
Click the [ lookup icon ] in the second [ field ] on the first [ Form block ] and select " Quantity ".
Click the [ lookup icon ] in the [ Operator field ] and select the " multiplication operator "
x
.Click the [ lookup icon ] in the first [ field ] on the second [ Form block ] and select " Buys ".
Click the [ lookup icon ] in the second [ field ] on the second [ Form block ] and select " Price ".
Click the [ lookup icon ] in the first [ field ] on the third [ Form block ] and select " Buys ".
Click the [ lookup icon ] in the second [ field ] on the third [ Form block ] and select " Fees ".
info
So far the statement is stating if
the current form equals Buys
perform the following:
Quantity * Price + Fees
and enter the value in the Total
field on the Buys
form
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Set Form block ] and connect with the [ if/do/else block ] in the
else
position.Click the [ lookup icon ] in the first [ field ] and select " Sells ".
Click the [ lookup icon ] in the second [ field ] and select " Total ".
Select [ Math ] in the [ toolbar ].
Click, hold, and drag the [ Equation block ] and connect with the [ Set Form block ].
Select [ Math ] in the [ toolbar ].
Click, hold, and drag the [ Equation block ] and connect in the first input position in the [ Equation block ].
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Form block ] to the first input position in the [ Equation block ].
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Form block ] to the second input position in the [ Equation block ].
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Form block ] to the third input position in the [ Equation block ].
Click the [ lookup icon ] in the first [ field ] on the first [ Form block ] and select " Sells ".
Click the [ lookup icon ] in the second [ field ] on the first [ Form block ] and select " Quantity ".
Click the [ lookup icon ] in the [ Operator field ] and select the " multiplication operator "
x
.Click the [ lookup icon ] in the first [ field ] on the second [ Form block ] and select " Sells ".
Click the [ lookup icon ] in the second [ field ] on the second [ Form block ] and select " Price ".
Click the [ lookup icon ] in the [ Operator field ] and select the " subtraction operator "
-
.Click the [ lookup icon ] in the first [ field ] on the third [ Form block ] and select " Sells ".
Click the [ lookup icon ] in the second [ field ] on the third [ Form block ] and select " Fees ".
info
The statement is now stating, if
the current form equals Buys
perform the following:
Quantity * Price + Fees
and enter the value in the Total
field on the Buys
form
else
, if we are on the Sells
form perform the following:
Quantity * Price - Fees
and enter the value in the Total
field on the Sells
form
Select [ Five ] in the [ toolbar ].
Click, hold, and drag the [ Return block ] and connect with the [ if/do/else block ].
Select [ Values ] in the [ toolbar ].
Click, hold, and drag the [ Quote block ] and connect with the [ Return block ].
Click the [ Save button ] in the [ Low-Code editor app bar ].
info
When interacting with Five's API a certain format is expected, Five needs to know if the function is successful when called to continue with the processing or know to terminate. A message can be added by typing in the Quote block. You can leave the message blank.
- Click the [ Save button ] in the [ form app bar ].
warning
If you click the Convert to JavaScript button, you cannot come back to the Low-code Editor side without breaking your blocks.