Automating Processes In Five: Using Jobs

Welcome to Five Labs, a step-by-step guide to building apps with Five.

This lab will guide you through the process of creating Jobs in Five. Jobs in Five are used to automate functions, allowing you to schedule and run them on a recurring basis. The objective of the tutorial is:

– Download and import the task management template into Five.

– Write and manage JavaScript functions.

– Add a reminder feature in the task management template.

– Job creation in five.

Laboratory objectives

By the end of this lab, you will have learned how to write Five Jobs that can execute your Five Actions on a recurring basis.

Typical use cases for jobs are, for example, scheduling an email report weekly, checking for new orders daily, or notifying users about incoming requests every minute. Five’s Jobs feature allows us to schedule features at regular time-based intervals.

To get started, here’s what we need:

– Have Five installed on your system or run Five in the cloud (with a paid subscription).

Don’t you feel like reading?

Watch the YouTube video and learn how to use jobs to schedule tasks in Five.

Step 1: Download and import the task management template

First, let’s import a template into Five so we can get a head start and after that, we can jump straight into our functions.

For this tutorial, we will use the Task Management Template and add a Reminder feature to this app so that we receive a notification every time a task is due.

Download the template from the link above and import it into Five.

Click the “Manage” button to enter the development environment, then select “Database Modeler” in the “Data” menu to view the application database.

The Task Management app is simple and consists of four database tables: Tasks, Reminders, Task Categories, and Categories.

It also includes some pre-designed forms, charts, and queries for your perusal. We will use the ‘Reminder’ table to create a simple reminder function for this app.

Step 2: Define JavaScript functions

Now that we understand our application, let’s start writing code.

Within Five, navigate to the “Code Editor,” which you can find within “Logic.”

Click the ‘+’ icon to start a new function. Give it a meaningful name (we’ll call it sendReminder) and choose your preferred language, either TypeScript or JavaScript.

We’ll start by retrieving all the reminder dates from our table. We can do this by invoking a simple SQL statement through our function.

function sendReminder(five, context, result) {

let sqlStatement = ‘Select reminder date from reminders’

let queryResults = five.executeQuery(sqlStatement, 0);

if (!queryResults.isOk()) {

five.createError(queryResults);

}

return five.success(result);

}

We use five.executeQuery()

and then we use.isOk()

to check if the response resulted in any errors. Since the response is a JSON object, we can easily map our results.

function sendReminder(five, context, result) {

let sqlStatement = ‘Select reminder date from reminders’

let queryResults = five.executeQuery(sqlStatement, 0);

if (!queryResults.isOk()) {

five.createError(queryResults);

}

queryResults.values.map(item => {

five.log(“Hello world”)

let currentDate = Date.now();

let reminderDate = new Date(item.ReminderDate)

if(currentdate>=reminderdate){

five.showMessage(“You have a pending task”)

}

})

return five.success(result);

}

We simply iterate over each date and compare the set reminder date with the current date; if appropriate, show a message using five.showMessage()

. We have also used five.log()

to test whether the function is working or not when we call it.

Now that our function is somewhat prepared, let’s test it first. We’ll start by attaching our function to a

Leave a Comment