Creating a Subprocess
How to create a reusable part to your Processes.
In Frends, a Subprocess is a special, reusable Process that can be executed from other Processes. Subprocesses are essential for encapsulating logic that can be shared across multiple integrations, promoting reusability and simplifying complex workflows. They can also be used to execute functionality in different Environments.
Step by Step Tutorial Available
If you prefer more visual or interactive guidance on how to create Subprocesses with Frends, you can find a step-by-step walkthrough from your own environment's home page, under Onboarding by selecting "Tutorial 3, Step 1: Creating a Subprocess" tutorial.
Creating a New Subprocess
Subprocesses are managed separately from main Processes.
Navigate to the Subprocesses section from the main menu.
From the Subprocess list view, ensure you are in the Development Environment.
Click the Create New button to open the Subprocess editor.

Just like with regular Processes, all development for Subprocesses happens in the Development Environment before they are deployed.
The Subprocess editor is nearly identical to the Process editor. However, a Subprocess can only be initiated by a Manual Trigger, as they are called from another Process, not run independently.
Let's create a Subprocess that performs customer data mapping for a Customers JSON array that is provided as parameter for it. The result value we expect is also JSON, but with different fields.
Configuring the Trigger
A new Subprocess starts with a Manual Trigger. This is where you define the input parameters that the calling Process will provide.

Select the Trigger shape.
In the right sidebar, under the Parameters section, click Add parameter.
Define the parameter:
Key:
CustomerArray
(This is the identifier used to access the parameter's value).Default value:
[]
(Provides empty array if no parameter is set).Description:
Customer data as JSON array
(Explanation of what is expected)
You can add multiple parameters as needed. It's also possible to mark parameters as secrets to prevent their values from being logged.

Adding shapes and Tasks
Next, we will add the necessary shapes to our Subprocess to perform iteration on the provided array, as well as mapping the data to a new format.
To perform iteration in a Process or Subprocess, we can use Foreach scope.
Drag a Foreach shape from the toolbar onto the canvas.
Select the Foreach shape to set up the iteration variable, as well as the container we iterate through.
Name:
Iterate Customers
Variable:
Customer
(Each element of the input array contains a customer)Expression:
JArray.Parse(#trigger.data.CustomerArray.ToString())
The
#trigger.data.CustomerArray
expression is used to access theCustomerArray
parameter we defined in the Manual TriggerParameters are provided to us as serialized JSON, thus we need to parse back into a JArray, or JSON Array object
Now we can use
#var.Customer
within the Foreach shape to access each customer's data.
Connect the Foreach shape to the Trigger by using Connect tool.

Next, add a Code Task inside the Foreach loop, which we will use to perform the data mapping in this use case. Connect it to the Start shape within the Foreach loop.
After adding the Code Task and connecting it, select the shape again to open its parameters.
Enable Assign variable to allow the Statement to return a value, which is the new Customer JSON object.
Give the resulting variable a name such as
NewCustomer
.Click on Frends Assistant button in bottom right corner to open it.
You can enter for example the following prompt to obtain a C# code snippet we can use for our Subprocess:
I want to convert the Customer data into another JSON format. I want to only include mainContact and companyName fields from the Customer, have them included as Name and Company fields in the resulting JSON object. Additionally, I want to generate a unique guid identifier for the object as field ID. Customer variable is already a JObject. Return the result as JObject.
The AI will provide you with a C# code. Click on Use to have it placed within your Code Task.

Configure the Return Value
Every scoped shape and also the Subprocess must end with a Return shape to pass data back to the calling Process. Let's first end the Foreach loop properly.
Append a Return shape to the Code Task inside the Foreach loop.
Set the Result to value
#var.NewCustomer
(Matching the Code Task's variable name).
When defining the return value for a Foreach shape, each iteration will generate its own result object, which are combined into an array object. Thus by returning the #var.NewCustomer
JSON object from the Foreach loop, we are essentially generating a new array of customer data as the result.

Finally, we need to end the Subprocess into another Return shape.
Drag a Return shape onto the canvas.
Connect the Foreach shape to the new Return shape.
Select the Return shape and configure its properties:
Expression:
#result[Iterate Customers]
(Targeting the Foreach shape by name)
The Subprocess should now be complete, and look like the Subprocess in the following picture.

Validate and Save the Subprocess
Once your Subprocess is complete, you need to save it.
Click the Validate button to check for any configuration errors.
You can add a comment to the version history to describe your changes, which is a recommended practice.
Click Save changes to save your Subprocess.
After saving, you will be returned to the Subprocess list, where your new Subprocess will be visible and ready for deployment and use in other Processes.
Last updated
Was this helpful?