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.

  1. Navigate to the Subprocesses section from the main menu.

  2. From the Subprocess list view, ensure you are in the Development Environment.

  3. Click the Create New button to open the Subprocess editor.

Subprocess view works almost identically to Processes view.

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.

Initial state for starting Subprocess creation.
  1. Select the Trigger shape.

  2. In the right sidebar, under the Parameters section, click Add parameter.

  3. 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.

Configuration of a Manual Trigger in a Subprocess with a 'Name' parameter.

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.

  1. Drag a Foreach shape from the toolbar onto the canvas.

  2. 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 the CustomerArray parameter we defined in the Manual Trigger

      • Parameters 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.

  3. Connect the Foreach shape to the Trigger by using Connect tool.

Subprocess with a Foreach loop added.

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.

  1. After adding the Code Task and connecting it, select the shape again to open its parameters.

  2. Enable Assign variable to allow the Statement to return a value, which is the new Customer JSON object.

  3. Give the resulting variable a name such as NewCustomer.

  4. Click on Frends Assistant button in bottom right corner to open it.

  5. 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.
  1. The AI will provide you with a C# code. Click on Use to have it placed within your Code Task.

Current state of our Subprocess, with Foreach and Code Task added.

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.

  1. Append a Return shape to the Code Task inside the Foreach loop.

  2. 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.

Returning a value from Foreach shape will build an array of the return values for each iteration.

Finally, we need to end the Subprocess into another Return shape.

  1. Drag a Return shape onto the canvas.

  2. Connect the Foreach shape to the new Return shape.

  3. 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.

Completed Subprocess starts with a Trigger shape, and all paths end to a Return or Throw shape.

Validate and Save the Subprocess

Once your Subprocess is complete, you need to save it.

  1. Click the Validate button to check for any configuration errors.

  2. You can add a comment to the version history to describe your changes, which is a recommended practice.

  3. 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?