Skip to main content

Create a Process

Last updated 27/03/2024

The following instructions show you how to add a process.

Add a Process

A process requires a function to be attached to perform a particular task. This documentation will show you how to add a process with your function already saved in Five. Alternatively, you can add your process, add your function, and edit your process record to attach your function.

For this example, the function is going to generate data and insert the data into the Rainfall table using Five's

function. As this is a backend function, it will need to be attached to the Do Run event.

Below is the sample code that is used for the Generate Rainfalls process.


JavaScript
Generate Rainfall Data
function GenerateRainfalls(five, context, result) {
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}

const station1 = '251b1054-0838-11f0-97d9-baf1e09a4b4b';
const station2 = '251b12ad-0838-11f0-97d9-baf1e09a4b4b';
const station3 = '251b14aa-0838-11f0-97d9-baf1e09a4b4b';
const date = new Date("2023-01-01T00:00:00");
for (let i = 0 ; i < 365; i++) {
five.executeQuery('INSERT INTO Rainfall (RainfallKey, StationKey, MeasurementDate, RainfallAmount) VALUES(?, ?, ?, ?)', -1, five.uuid(), station1, date, randomIntFromInterval(0, 7));
five.executeQuery('INSERT INTO Rainfall (RainfallKey, StationKey, MeasurementDate, RainfallAmount) VALUES(?, ?, ?, ?)', -1, five.uuid(), station2, date, randomIntFromInterval(0, 7));
five.executeQuery('INSERT INTO Rainfall (RainfallKey, StationKey, MeasurementDate, RainfallAmount) VALUES(?, ?, ?, ?)', -1, five.uuid(), station3, date, randomIntFromInterval(0, 7));
// Add a day
date.setDate(date.getDate() + 1)
}

return five.success(result);
}

1. Navigate to the Processes view be selecting Tasks in the menu and Processes in the sub-menu.


Processes menu item
Figure 1 - Processes menu item

2. Click the Add Item button and give your Process a title.


Add process
Figure 2 - Add process

3. Click the Events tab.


Events-tab
Figure 3 - Events tab

4. Click the lookup icon in either the On Run field or the Do Run field and select your function.

info
For this particular example, the function is being attached to the Do Run field as this is a backend function.

Do Run event
Figure 4 - Do Run event

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


Save button
Figure 5 - Save button

6. Create a menu for your process.


Generate Rainfalls menu item
Figure 6 - Generate Rainfalls menu item

In the Rainfall application, the station located in New York only has two rainfall records.


New York rainfall
Figure 7 - New York rainfall

We can run the Generate Rainfalls process by clicking the Run button in the toolbar.


Generate Rainfalls process
Figure 8 - Generate Rainfalls process

On successful completion we will be notified in the Notifications bell.


Success notification
Figure 9 - Success notification

If we come back to the New York station, 365 extra records have been generated from our process. 365 records have also been generated for the stations located in London and Sydney.


Generated rainfalls records for New York
Figure 10 - Generated rainfall records for New York