Skip to main content

Functions and Events Used in the ROS Application

Last updated 19/01/2022

How to Add a Function and Attach it to an Event

The following video shows how to write a function in Five and attach it to an event.




Steps

1. Select Functions in the menu.

2. Click the Add Item button in the list app bar.

3. Type an ID in the Function ID field.

4. Click the lookup in the Language field and select a language.

5. Click in the Code field to open Five's Code Editor.


Add a Function
Figure 1 - Add a function


6. Type your code in the editor.

7. Click the Save button in the editor.


Add the Code
Figure 2 - Add the code

8. Click the Save button in the form app bar.


Save the Function
Figure 3 - Save the function

9. Select the menu item you need to attach the function to.

10. Select the record in the list.

11. Click the Events tab.


Events Tab
Figure 4 - Events tab

12. Click the lookup icon in an event field and select the function ID.

13. Click the Save button in the form app bar.


Attach the Function and Save the Record
Figure 5 - Attach the function and save the record

AssignRole()


FormEventExecutesFunction Example
ApplicationsDo LogonServerAssignRole()

To execute the validation set on the Show If and Read Only If fields on the Orders form:

(form.variable.Role === 'Dispatch')

The AssignRole() function was created and attached to the Do Logon event on the Applications form. The Do Logon event executes when a user logs into the system and authentication is successful. The AssignRole() will then be called and calculates the role of the user and stores it in a session variable which the above condition can use to determine the accessibility using the Show If and Read Only If fields.

DispatchCompleteOrder()


FormEventExecutesFunction Example
FormDo CompleteServerDispatchCompleteOrder()

The DispatchCompleteOrder() will execute when the Save button is clicked for the Orders form. The DispatchCompleteOrder() will be called and calculates the full name of the dispatch user to store in a notification to the client (Restaurant) informing their order has been completed.

If an error occurs on the Orders form, this includes the Items sub-form, the data will not be saved to the database.

ValidDiscountCode()


FormEventExecutesFunction Example
FormsOn ValidateClientValidDiscountCode()

The ValidDiscountCode() will execute and show a message if a discount code entered on the Item's form Discount Code field does not match one of the codes in the array of the ValidDiscountCode function.