Written for Frends version 5.1

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:

  1. Editor access to your Frends tenant to access the Process editor view.

  2. An Agent Group and Environment setup up to run Processes.

  3. The Task called 'Frends.Cobalt' imported to your Frends tenant. 

  4. Source FTP 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 value test.rebex.net

  • #env.ConditionalTrigger.SftpUsername  with value demo 

  • #env.ConditionalTrigger.SftpPassword with value password  (in secret field) 

  • #env.ConditionalTrigger.Filename  with value readme.txt 

Creating a Subprocess

A new Subprocess can be created by navigating to the Subprocesses view and clicking the + Create new button.

Add FTP handler 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 Cobalt. The Cobalt task is a multipurpose and flexible task that can both upload and download files from multiple different sources.

In this example we are going to configure information under Source and Destination tabs in the Cobalt parameter editor. In source Cobalt is configured to use credentials and addresses stored in environment variables. In addition file name is taken from Environment variable. In destination local filesystem is used as target and only directory need to be defined.


Exclusive decision shape is used to determine if files have been read from SFTP share. Cobalt returns number on transferred files in SuccesfulTransferCount  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 Processes  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.  

  1. Drag a Start shape to the canvas from the BPMN toolbar.

  2. Select Conditional  from the Type  dropdown in parameter editor on the right side of the canvas.

  3. Subprocess created before can be selected from dropdown menu. 

  4. Poll interval in seconds  can be leave to 60. This defines how often the subprocess is run.

Add delete task

Next we add task Frends.File.Delete can 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 change username in #env.ConditionalTrigger.Username  and thus produce login error, that will show in FRENDS UI in both process and Subprocess lists.

Did this answer your question?