SubFlow
![](https://docs.deepser.com/wp-content/uploads/2023/10/image-1.png)
SubFlows are flows which have the purpose of performing common operations between several flows, and can also be seen as functions which can be called across flows.
Configuring a sub flow
Sub flows in Deepser can be seen as functions that can be called up in various flows to perform common operations between the various flows.
In this article we are going to configure a Sub Flow that will take care of changing the status of the operation associated with an activity.
Configuring the
subflowTo do this you will need to go to the Flow -> Designer menu.
Now you will need to click the NEW button in the upper left corner of the page:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image003-7.png)
And then on the word “Sub Flow” that will appear below the button
At this point the following page will open:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image002-7-1.png)
Below are the fields with their meaning:
- Name, in this field we are going to define the name that this flow will have.
- Description, in this field we are going to define the description that will have the flow
- Icon, in this field we are going to define the icon that will have the flow
- Enable Log, this toggle if set to you will enable the log in the flow.
Once you have configured the fields mentioned above you will need to click on the “Save” button.
Now the following screen will appear:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image003-11.png)
In the “INPUTS & OUTPUTS” block we will configure the inputs and autput of the function.
In our case the block “INPUTS & OUTPUTS”, will be configured as follows:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image004-8.png)
Once you have configured this block you will need to configure a “Lookup Record” block that we will configure as follows:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image005-7.png)
Below the previous block we must insert a “Script” block with the following configuration:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image006-10.png)
The script will take in input the operation retrieved from the lookup records block and the new state, provided to the invocation of the SubFlow and will provide in output an integer that will be worth zero if the update operation was not successful and 1 if the status of the operation has been changed.
In the Espression (Script) field we will have to enter the following code:
$operation = $this->getInput('operation');
$status = $this->getInput('status');
if($status && $operation && $operation->getId()){
$operation->setStatus($status);
$operation->save();
$this->setOutput('done', 1);
}else{
$this->setOutput('done', 0);
}
Finally we will have to add a block “Assign Values To Output” present in the “Logic” section, configured as follows:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image008-6.png)
Finally, to finish the SubFlow you will need to enter an “EndFlow” block.
Before you can use the newly created subflow you will need to enable the sub flow by setting the “Status” toggle as follows:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image017.png)
At this point the sub flow will be up and running
Using a sub flow
In our example we are going to create a new flow that will be performed when a new activity is created and that will call the newly created sub flow.
To do this you will need to go to the Flow -> Designer menu.
Now you will need to click the NEW button in the upper left corner of the page:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image003-7.png)
And then on the word “Flow” that will appear below the button
At this point the following page will open:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image010-6.png)
Below are the fields with their meaning:
· Name, In this field we are going to define the name that this flow will have.
· Description, In this field we are going to define the description that will have the flow
· Icon, in this field we are going to define the icon that will have the flow
· Enable Log, this toggle if set to you will enable the log in the flow.
Once you have configured the fields mentioned above you will need to click on the “Save” button.
Now the following screen will appear:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image011-5.png)
At this moment we are going to configure the “Trigger” field as follows:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image012-4.png)
Now you will need to click on “Save” to save the block.
At this point we will have to go and click on the button:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image010-1.png)
At this point we will have to click on the “Sub Flow” section, we will have to select the sub flow that we have created:
Which will be configured in the following way:
![](https://docs.deepser.com/wp-content/uploads/2023/10/image014-5.png)
Under this block we will add an if block that will check if the status of the work has been changed, verifying the return flag, or not.
If the status has not been changed, it will print a message in the flow log to have visibility of the changes.
Before you can see the effects of the flow you will need to enable the flow by setting the toggle “Status”
![](https://docs.deepser.com/wp-content/uploads/2023/10/image015-3.png)
At this point the flow will be up and running