Written for Frends version 5.5
This guide shows how a Conditional Trigger can be used to start a Process. In this guide a file named readme.txt is searched from a SFTP folder, and if it is there it is downloaded to Frends. If the file is not found, the calling Process is not run, if the file is found and downloaded the calling Process is started and it will just delete the downloaded file.
Prerequisites
You will need the following prerequisites to follow through with this guide:
Editor access to your Frends tenant to access the Process Editor View.
An Agent Group and Environment setup up to run Processes.
The Task called 'Frends.SFTP.DownloadFiles' imported to your Frends tenant.
Source SFTP server. In this guide we will use the free https://test.rebex.net/ server available for testing.
First, Environment Variables are created to store information related to SFTP server. A Conditional Trigger works by starting defined Subprocess periodically, e.g. once a minute. If that Subprocess then returns something other than null
or empty string ""
the Process containing the Conditional Trigger is then run. In other words, the start of Process is defined by a Subprocess and therefore we create that Subprocess and the last step is to create the actual Process.
Creating Environment Variables
To store login information and a file four Environment Variables are used, so they can easily be changed in the future:
#env.ConditionalTrigger.SftpAddress
with valuetest.rebex.net
#env.ConditionalTrigger.SftpUsername
with valuedemo
#env.ConditionalTrigger.SftpPassword
with valuepassword
(in secret field)#env.ConditionalTrigger.Filename
with valuereadme.txt
Creating a Subprocess
A new Subprocess can be created by navigating to the Subprocess List View and clicking the + Create new
button.
Add SFTP Task
The next step in creating a Subprocess is to add a Task that can fetch the file from the source SFTP server. We are going to use a task called SFTP.DownloadFiles. The Task can be used for fetching files from SFTP server.
In this example we are going to configure information under Source
and Destination
tabs in the Task's Parameter Editor. In source the Task is configured to use credentials and addresses stored in Environment Variables. In addition file name is taken from Environment Variable. In destination only directory needs to be defined.
Exclusive Decision Element is used to determine if files have been read from SFTP server. The Task returns number on transferred files in SuccessfulTransferCount
that can be used to check if files have been found and transferred.
If files are read, filename is returned to parent Process. TransferredFileNames
contains a list of names of transferred files. Here we know that only one file is transferred and want to pass on only its name, so name can be extracted from list by calling First()
method.
If nothing is found empty string ""
is returned to parent Process, as it tells Frends that Process contain Conditional Trigger should not run, returning null
would work here as well.
Creating a Process
A new Process can be created by navigating to the Process List View and clicking the + Create new
button.
Add Conditional Trigger
Basically Conditional Trigger works by defining Subprocess used and how often it is run. If you want additional information about Conditional Triggers you can read the documentation.
Drag a Start Element to the Canvas from the Toolbar.
Select
Conditional
from theType
dropdown in Parameter Editor on the right side of the Canvas.Subprocess created before can be selected from dropdown menu.
Poll interval in seconds
can be left to 60. This defines how often the Subprocess is run.
Add delete Task
Next we add Task Frends.Files.Delete to delete local files. It will need folder and name of file being delete. Filename can be taken from Trigger data as it has been passed from Subprocess.
Process testing
The Process should now be ready to run. Conditional Trigger will start polling SFTP server when the Process is activated, but before that is done the log level for the Process should be set to everything for a couple of minutes, so the execution of the Subprocess in Conditional Trigger actually gets logged. If logging is set to Default
or Only errors
the Subprocess only gets logged if there is an error inside of it. As the readme.txt should always be found on SFTP server, the Process should be started once a minute if everything is working.
If you want to observe how Conditional Trigger works when a file is not found, and thus the Process is not started you can change the filename in #env.ConditionalTrigger.Filename
to something else. If you want to observe what happens when an error occurs in Subprocess in Conditional Trigger, you can modify the destination directory to something random in the Subprocess to produce exception during the Task execution.