Skip to content

Commit 93880b2

Browse files
committed
Microflows
1 parent 5f60653 commit 93880b2

1 file changed

Lines changed: 39 additions & 25 deletions

File tree

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-10/extensibility-api/csharp/extensibility-api-howtos/create-microflow-service.md

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ weight: 14
77

88
## Introduction
99

10-
The `IMicroflowService` is the service used to perform actions related to microflows. This how-to describes how you can create a new microflow and add some activities to it.
10+
This how-to describes how to create a new microflow and add activities to it. The `IMicroflowService` is used to perform actions related to microflows.
1111

12-
## `Initialize`
12+
## Creating and Initializing a Microflow Using `Initialize`
1313

14-
The `Initialize` method initializes a microflow that was previously created. It is part of a series of steps required for adding a microflow to the model:
14+
The `Initialize` method initializes a microflow that was previously created. Follow the steps below:
1515

16-
1. Start a transaction (`IModel.StartTransaction`).
17-
2. Create a microflow and add it to the module (`IModel.Create<IMicroflow>`).
18-
3. Call `IMicroflowService.Initialize`.
19-
20-
Internally, the `Initialize` method sets up the start and end flows, and adds any parameters that might be passed in (in the example below, you are passing a single parameter `boolParameter` of `DataType.Boolean`).
21-
22-
In the example below, you also add activities to the microflow, with `IMicroflowService.TryInsertAfterStart` (adding an activity as the first) or `IMicroflowService.TryInsertBeforeActivity` (adding an activity before another).
16+
1. Start a transaction using `IModel.StartTransaction`.
17+
2. Create a microflow and add it to the module. Use `IModel.Create<IMicroflow>` to create the microflow and add it to the desired module.
18+
3. Initialize the microflow by calling `IMicroflowService.Initialize`. The `Initialize` method sets up the start and end flows, and adds any parameters (for example, `boolParameter` of `DataType.Boolean`).
19+
4. Insert activities into the microflow using `IMicroflowService.TryInsertAfterStart` to add the first activity, and `IMicroflowService.TryInsertBeforeActivity` to insert activities before others.
2320

2421
```csharp
2522
public void Initialize(IModel currentApp, params IActionActivity[] actionActivities)
@@ -47,16 +44,22 @@ public void Initialize(IModel currentApp, params IActionActivity[] actionActivit
4744
}
4845
```
4946

50-
As you can see, this `IMicroflowService.Initialize` method can be cumbersome to use, since it is only part of the whole process of creating a new microflow. To have an easier method of creating microflows, use the `MicroflowService.CreateMicroflow` method. This method is described in the next section.
47+
Note that this `IMicroflowService.Initialize` method requires multiple manual steps. For a simpler approach, use the `MicroflowService.CreateMicroflow`, described in the section below.
5148

52-
## `CreateMicroflow`
49+
## Creating a Microflow Using `CreateMicroflow`
5350

54-
The `CreateMicroflow` method is the more advanced and comprehensive method to create microflows. It is a good alternative to the `IMicroflowService.Initialize` method.
55-
The `CreateMicroflow` takes care of initialization and adding everything to the model in one single step. It requires the current `IModel`, the `IFolderBase` (module or folder) in which to save the microflow, a name, an optional `MicroflowReturnValue`, and an optional list of parameters. See the code below for a few examples.
51+
The `CreateMicroflow` method is the more advanced and comprehensive method to create microflows. It is an alternative to the `IMicroflowService.Initialize` method. The `CreateMicroflow` method handles initialization and model integration in one step. It requires:
52+
53+
* The current `IModel`
54+
* `IFolderBase` (module or folder)
55+
* A name
56+
* Optional:
57+
* `MicroflowReturnValue`
58+
* List of parameters
5659

5760
### Creating a Simple Microflow
5861

59-
As shown in the code below, all that is required to create a microflow and add it to the model is the `IModel`, the `IFolderBase` in which to add the microflow, and its name.
62+
As seen in the code below, the only requirements are `IModel`, the `IFolderBase`, and its name.
6063

6164
```csharp
6265
public void CreateMicroflow(IModel currentApp)
@@ -73,7 +76,7 @@ public void CreateMicroflow(IModel currentApp)
7376

7477
### Creating Microflow with Return Type and Parameters
7578

76-
In this more advanced example, you will see the `IMicroflowExpressionService.CreateFromString` method, which allows you to create expressions that can be then used as the `MicroflowReturnValue` of the microflow. Here, the expression is a simple addition of two values, and the return type is of `DataType.Integer`.
79+
In this more advanced example, you see the `IMicroflowExpressionService.CreateFromString` method, which allows you to create expressions that can be then used as the `MicroflowReturnValue` of the microflow. Here, the expression is a simple addition of two values, and the return type is of `DataType.Integer`.
7780

7881
```csharp
7982
void CreateMicroflow(IModel currentApp)
@@ -88,36 +91,47 @@ In this more advanced example, you will see the `IMicroflowExpressionService.Cre
8891
}
8992
```
9093

91-
The `IMicroflowService.CreateMicroflow` method is a bit easier to use than the `IMicroflowService.Initialize` method because it doesn't require manually creating the microflow with `IModel.Create<IMicroflow>` and then manually adding it to the `IFolderBase` container. It can do everything behind the scenes as long as everything is supplied to it. For a comprehensive example on how to create microflows, see [Create Microflows for Calculations Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-10/create-microflows-for-calculations/).
94+
The `IMicroflowService.CreateMicroflow` method does not require manually creating the microflow with `IModel.Create<IMicroflow>`, then manually adding it to the `IFolderBase` container. For a comprehensive example on how to create microflows, see [Create Microflows for Calculations Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-10/create-microflows-for-calculations/)
95+
96+
## Inserting Activities
9297

93-
## `TryInsertAfterStart` and `TryInsertBeforeActivity`
98+
Use the following methods to insert activities into microflows:
9499

95-
The `TryInsertAfterStart` and `TryInsertBeforeActivity` methods enable inserting an activity in the flow. It can be added right after the start event of the microflow, or be inserted before another specific activity.
100+
* `TryInsertAfterStart` – adds an immediately after the start event
101+
* `TryInsertBeforeActivity` – inserts an actvitiy before another specific activity
96102

97103
```csharp
98104
microflowService.TryInsertAfterStart(microflow, newActivity);
99105
microflowService.TryInsertBeforeActivity(newAactivity, existingActivity);
100106
```
101107

102-
## `GetParameters`
108+
## Retrieving Microflow Parameters
109+
110+
Use `GetParameters` method to retrieve all the input parameters of a microflow.
111+
112+
It returns a list of `IMicroflowParameterObject`, which includes:
113+
114+
* Name
115+
* `IQualifiedName` identifier
116+
* Description
117+
* `DataType`
103118

104-
The `GetParameters` method enables retrieving all the parameters that are inputs into a microflow. It returns a list of `IMicroflowParameterObject`, which is composed of its name, its `IQualifiedName` identifier, a description, and its `DataType`. Any parameters passed into the microflow will be returned here together with their type.
105119

106120
```csharp
107121
IReadOnlyList<IMicroflowParameterObject> parameters = _microflowService.GetParameters(microflow);
108122
```
109123

110-
## `GetAllMicroflowActivities`
124+
## Retrieving Microflow Activities
111125

112-
The `GetAllMicroflowActivities` method enables retrieving all the activities in the flow of a microflow. It returns a list of `IActivity`.
126+
Use the `GetAllMicroflowActivities` method to retrieve all the activities in the flow of a microflow. It returns a list of `IActivity`.
113127

114128
```csharp
115129
IReadOnlyList<IActivity> activities = _microflowService.GetAllMicroflowActivities(microflow);
116130
```
117131

118-
## `IsVariableNameInUse`
132+
## Checking for Variable Name Conflicts
119133

120-
The `IsVariableNameInUse` method can check if the microflow already contains a variable with the name provided. This can be called before adding a new activity to the flow whose output variable name can overlap with existing variables. An example is as follows:
134+
Use the `IsVariableNameInUse` method to check if the microflow already contains a variable with the name provided. This can be called before adding a new activity to the flow whose output variable name can overlap with existing variables.
121135

122136
```csharp
123137
public void AddNewActivity(IModel currentApp, IMicroflow microflow, string activityName)

0 commit comments

Comments
 (0)