Table of Contents

Advanced use of workflows

How a Developer can work with Workflows

Different type of triggers

currentRecord
user
organisation
variables 

currentRecord.f_some_field = ‘something’
variables.x = 10;

Workflow triggers

Workflow can be triggered on “create” of the record or on “update” of the record.

The workflow can also be triggered with a user defined time interval. If special time based definitions is required, that can be done using a cron job. 

 

 

Workflow trigger

Create trigger

Chose “On Create” 
Define a filter if the workflow should not run on all new records
 
Filter can be simple referencing to a static value or they can be advanced, referring to a dynamic value  such as currentRecord or user, You can create a simple “one liner script on available data offent used is something like 
the property value is before 10days from now 

 

 

Script in filter

Update trigger 

Chose “On Update” then the rest is like ” Create trigger

 

 

Scheduled trigger

Creating a scheduled job can be done by

Chose “Scheduled” 

and define the interval in seconds, minutes, hours or days

Workflow configure a schedule

when setting up a scheduled job, you should always add a filter, to define the records that will be impacted by the job, normally leaving out done and cancelled tasks are left out.

Scheduled job warning

Cron Job

 

It can also be some what more advanced by selecting “Cron” instead of “Interval”,

The “Cron” option gives you a large verity of options.

It is basically 5 values that can be included. 

* * * *  *

min hours date month weekdays

 min starts a 0 goes to 59

hours start at 0 goes to 23

dates start at 1 goes to 31

months start at 1 goes to 12

you can select 0-4 or 0,1,2,3,4 there are no space between different same options

every quarter is */15,  if it  should start at the 3rd minute 3/15

every 3rd day is */3

The months have the same values and options but do also have JAN-DEC

the weekdays starts at sunday (0) having the same values and options but do also have SUN-SAT

 

We found a few ressources explaining cron jobs in details, by googling “cron job generators.  the one used last is this one https://crontab-generator.org

Cron job

Working with time

In your scripts you can work with time…

// variables.timeToGo in hours
var now = new Date().toISOString()
variables.timeToGo = ( Date.parse( currentRecord.f_deadline )
Date.parse( now))/1000/60/60;
 
await Mail.send(‘john@done.com’, ‘This issue for you’,
currentRecord.f_title);
// Variables
const listApiName = “ansaettelsessystem”;
const data =
{
filters: {
type: ‘FILTER_GROUP’,
logicalOp: ‘AND’,
filters: [
{
type: ‘FILTER’,
fieldApiName: ‘f_tite’,
comparator: ‘contains’,
value: ‘chef’
}
],
}
}
// Run the methods and store the result in a variable
const result = await Record.getAll(listApiName, data)
// Test print the result
var res = result.items // JSON.stringify(result.items)
var text=“”;
for (let i = 0; i < res.length; i++) {
text += res[i].f_tite +
;
}
 
currentRecord.f_text= text ;

Create record in a table

//Variables
const listApiName = “sagsbehandling”;
const data = {
“f_title”: currentRecord.f_title,
“f_sagsid”:variables.id
};
//Get field api names for the new data set
const result = await Record.create(listApiName, data);

Working with time and date

variables.x= currentRecord.f_deadline
var y= new Date().toISOString()
//z is duration in hours
variables.z = ( Date.parse( variables.x )
Date.parse( y))/1000/60/60;

Delete all record in a table

// Variables
const listApiName = “table”;
const params = “”;
// Run the method and store the results in a variable
const result = await Record.getAll(listApiName);
// Test print the result
for(x=0;x< result.items.length;x++){
await Record.delete(listApiName,result.items[x].id);
 
}

Delete all records in a table

const listApiName = “table”;
const params = “”;
const result = await Record.getAll(listApiName);
// Test print the result
 
for(x=0;x< result.items.length;x++){
await Record.delete(listApiName, result.items[x].id);
}

Delete all records in a table

const listApiName = “table”;
const params = “”;
const result = await Record.getAll(listApiName);
// Test print the result
 
for(x=0;x< result.items.length;x++){
await Record.delete(listApiName, result.items[x].id);
}

Recommandation

We recommend if you have dependent async calls (await) that you put them into different activities, since they might take a longer time to get the response. In this way you will make sure the workflow work, and it’s easier for you to check for errors in the log. 

Like if you are calling “get record” before updating the record.

If reference values are blank in the workflow log then workflow user of that list might not have access to the referred list.

Workflow execution

Workflow execution can time out. 

If you create an external call, you should make sure that the source you are triggering reponses (umiddelbart), since the workflow activities are not designed for waiting. 

Build in classes

List

Record

Mail

Use the API

How a developer can utilise the Rest API (outbound)

How a developer can utilise the Rest API (indbound

bob pressley