Workflow Logic
Logical blocks in deepser workflows are very important as they allow the flow of code execution to be redirected.
In this lesson we are going to deal with Logical Blocks in Deepser Workflows.
IF Conditional Block
In this article we are going to analyze the behavior of the conditional block “IF”.
The conditional block “IF” is part of the flow control instructions as it allows to direct the flow towards the execution of some blocks or others based on the veracity of the condition that characterizes it.
The “IF” block is located in the menu: Logic, to access it you will also need to click on the search bar that will appear:
The “IF” block visually will have 2 branches: the left ramo or the branch that will be executed if the condition is evaluated false, this branch is to be considered the continuation of the execution of the flow, and the right branch that will be executed if the condition is evaluated as true.
Note: If an else block is not indicated in the left ramp or an “End Flow” block is not specified in the right branch after the last instruction the flow will first execute the right branch and then the left branch.
EXAMPLE OF CONFIGURATION OF THE “IF” BLOCK
Suppose that when creating an operation we want to assign a specific mailbox if the type of service is “Incident”.
The “IF” block will then be configured as follows:
And the flow will then turn out to be:
Now in the right branch we are going to insert a block “Update Record” configured as follows:
The flow will eventually turn out to look like this:
Once this flow is activated we will see that the new “Incident” Operations will have as a mailbox box the one defined in the flow.
ELSE Conditional Block
In this article we are going to analyze the behavior of the conditional block “ELSE”.
The conditional block “ELSE” is part of the flow control instructions as it allows you to direct the flow towards the execution of some blocks or others based on the veracity of the condition that characterizes the Associated “IF” block.
It goes into fact said that the block “ELSE” to be used needs an associated block “IF”.
The ELSE block is located in the menu: “Logic”, to access it you will also need to click on the search bar that will appear:
The “ELSE” block visually will have 2 branches: the left branch that is to be considered the continuation of the execution of the flow, and the right branch that will be executed if the condition of the associated “IF” block is evaluated as false.
Note: If an “End Flow” block is not indicated in the right branch after the last instruction, the flow will first execute the right branch and then the left branch.
EXAMPLE OF CONFIGURATION OF THE “ELSE IF” BLOCK
Suppose you want to create a flow that when a new operation is created, automatically assigns the priority, assigning high priority if the urgency is high, otherwise you automatically assign medium priority.
To do this we will have to add an “If” block configured as follows:
Now in the right branch we are going to insert a block “Update Record” configured as follows:
In the left branch we are going to insert a “ELSE” block and in its right branch we will insert an “Update Record” block configured as follows:
The flow at the end will turn out to be as follows:
ELSE IF Conditional Block
In this article we are going to analyze the behavior of the conditional block “ELSE”.
The conditional block “ELSE IF” is part of the flow control instructions as it allows you to direct the flow towards the execution of some blocks or others based on the veracity of the condition that characterizes the Associated “IF” block and the condition that characterizes it.
It goes into fact said that the block “ELSE IF” to be used needs an associated block “IF” and can be associated with one or more blocks “ELSE IF” but with a single block “ELSE”.
The block “ELSE IF”, is located in the menu: Logic, to access it will be in addition necessary to click on the search bar that will appear:
The “ELSE IF” block visually will have 2 branches: the left branch that is to be considered the continuation of the execution of the flow, and the right branch that will be executed if the condition of the associated “IF” block is evaluated as false and the condition specified in the “ELSE IF” block is evaluated as true.
Note: If an else block is not indicated in the left ramp or an “End Flow” block is not specified in the right branch after the last instruction the flow will first execute the right branch and then the left branch.
EXAMPLE OF CONFIGURATION OF THE “ELSE IF” BLOCK
Suppose we want to extend the flow we created in the previous article.
Suppose you want to assign the newly created operation low priority in case the urgency is low.
To do this we will have to add a block “ELSE IF” before the ELSE block, to do this we will have to position ourselves on top of the else block and click the “+” symbol that will appear:
Once clicked we will have to enter from the “Logic” menu an element “ELSE IF” configured as follows:
In the right branch of the block “ELSE IF” go to insert a block “Update Record”, with the following configuration:
The flow in the end will turn out to be the following:
FOREACH Block
In this article we are going to analyze the behavior of the “FOREACH” block.
The “FOREACH” block is a block that allows you to iterate on collections of entities in Deepser and perform one or more actions for each entity in the collection.
The block “FOREACH”, is located in the menu: Logic, to access it will be necessary to click on the search bar that will appear:
The “FOREACH” block visually will have 2 branches: the left branch that is to be considered the continuation of the execution of the flow, and the right branch in which you will have to place the actions to be performed for each iteration of the cycle
Note: If you insert an end flow block in the left branch you will get the result of ending the execution of the flow.
EXAMPLE OF CONFIGURATION OF THE “FOREACH” BLOCK
Suppose we want to send an email notification to the user who created a password in the password manager when it is expired, for this example we will consider expired a password whose Expired field (field managed by a system automatism) is set to yes.
To do this we must initially recover the collection of entities of type “DeepPassword – Password” expired, to do so we will have to go to insert a block “Lookup Records” configured in this way:
At this point we can iterate on the password entities by adding below the previous block a “FOREACH” block, in whose right branch we are going to insert a “Send Email” block:
The “FOREACH” block will be configured as follows:
While the “Send Email” block will be configured as follows :
WHILE Block And Assign value to Variable block
WHILE Block
In this article we are going to analyze the behavior of the “WHILE” block.
The “WHILE” block is a block that allows you to iteratively perform operations
The “WHILE” block is located in the menu: Logic, to access it you will also need to click on the search bar that will appear:
The “WHILE” block visually will have 2 branches: the left branch that is to be considered the continuation of the execution of the flow, and the right branch in which you will have to place the actions to be performed for each iteration of the cycle
Note: If you insert an end flow block in the right branch you will get the result of ending the execution of the flow immediately, similar to what would happen with a break statement in classical programming.
Assign value to Variable block
The “Assign value to Variable” block allows you to assign an arbitrary value or the result of processing to a variable.
EXAMPLE WHILE Block Configuration
Suppose you want to create a series of task review tasks to assign to the ticket assignee, one per month for a total of 10 months.
We assume in addition that we want to calculate the date to and save it in a custom field “Two Dates”
To do this you will need to configure the flow trigger as follows:
At this point we will have to add a script block that will allow us to define an iteration variable for the “WHILE” cycle.
The Script block will be configured as follows:
Now we can go to add from the Logic section the block “WHILE”, which we will configure in this way:
In the right branch we are going to add now a new script block that will take care of performing the increment of the variable and also of calculating the duedate date within which to do the review of the operation.
The script will then be configured like this:
In the “Expression (Script)” field, we are going to enter the following code:
$iterator = $this->getInput('iterator');
$operation = $this->getInput('operation');
$expirationDate = new DateTime($operation->getCreatedAt());
$interval = new DateInterval("P{$iterator}M");
$expirationDate->add($interval);
$this->setOutput('exp_date',$expirationDate->format('Y-m-d'));
$this->setOutput('iterator2', $iterator+=1);
Below the previous block we will have to add a “Create Record” block, which we will configure to create a task at each iteration with the variables calculated by the previous script.
For the creation of tasks, the block “Create Record” you can refer to the image below:
Note: If you do not specify the “Model Id” and “Model Alias” fields, the tasks created will not be displayed in the ticket.
As a last block we will have to insert a block “Assign Value to Variable” configured as segune:
Now the final result will be as follows:
TRY – CATCH End Flow
CONSTRUCT TRY – CATCH
The try-catch construct is a block that allows you to capture the exceptions that can be generated by the various blocks of Deepser flows.
It consists of two blocks respectively the Try block and the catch block.
In the right branch of the try block you will have to insert the blocks of which we want to capture any exceptions, in the left branch a Catch block will be placed, which in turn will perform the actions placed in its right branch if and only if an exception will be generated in the try block.
EXAMPLE OF CONFIGURATION OF THE “TRY – CATCH” BLOCK
Suppose you want to run a script that might throw an exception during its execution, and you want to log in a custom error message if an exception is raised.
To do this we are going to insert a try block in whose right branch we are going to insert a “Script” block, in which we are going to insert the following code:
$operationCollection = Deep::getResourceModel('deep_service/operation');
$operationMap = $operationCollection->toOptionHash();
//.... rest of the code
Note: In our example we are going to deliberately insert a block of code that contains an errorn so that we can test the TRY-CATCH construct in particular the alias to get the Operation collection is “deep_service/operation_collection” and not “deep_service/operation”, which is the alias to retrieve a single operation.
Then the script block will be configured like this:
In the left branch of the try block we are going to insert a “Catch” block which in turn will have a desta branch in which we are going to insert our custom logging function.
In particular, in the right branch of the catch block we are going to insert a “Log” block configured as follows:
Below the “Log” block We will have to go and insert an “End Flow” block, in the specific case it can be avoided since there are no other actions to be performed, but in a more general case it may be sensible to exit the flow in case an exception occurs.
At this point the result will look like this:
Block Assign Value to Outputs
The Assign Value to Outputs block is a block that can only be used in subflows to set the value of an output.
When inserted in a Sub Flow, where there is at least one output, the block will be rendered as follows:
If the block is used a flow will be displayed as follows:
Example of “Assign Value to Outputs” Block configuration
Suppose you want to create a subflow that takes care of incrementing an integer variable passed in input to the subflow itself.
To do this we are going to create a new Sub flow whose “INPUTS & OUTPUTS” section will be configured as follows:
Now Let’s add a “Script” block configured as imagined here:
In the “Expression (Script)” section we will then insert the following code:
$input = $this->getInput('input');
$increase = $this->getInput('increase');
$this->setOutput('output',$input+$increase
After the script block, We will have to go to include the block “Assign Value to Outputs” and we will configure it to set in the output “output” the value increased by the script:
Finally we will have to activate the SubFlow to make it available to flows.