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
Below is the sample code that is used for the Generate Rainfalls process.
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.

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

3. Click the Events tab.

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

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

6. Create a menu for your process.

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

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

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

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.
