You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/csharp/extensibility-api-howtos/create-microflows-calculations.md
+48-21Lines changed: 48 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,17 @@ weight: 8
7
7
8
8
## Introduction
9
9
10
-
This how-to describes how you can create microflows which perform some calculations and return the result.
10
+
This how-to describes how to create microflows that perform calculations and return the result.
11
11
12
-
You can download the example in this how-to in[this GitHub repository](https://github.com/mendix/ExtensionAPI-Samples).
12
+
You can download the example in this how-to from[this GitHub repository](https://github.com/mendix/ExtensionAPI-Samples).
13
13
14
-
## Creating an Extension Class that Creates Microflows
14
+
## Creating an Extension Class That Creates Microflows
15
15
16
-
1. Open the project that you previously created when you [created a menu extension](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
17
-
2. Add a new folder *MicroflowTutorial* to your solution.
16
+
1. Open the project you created when following [Create a Menu Extension](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
17
+
2. Add a new folder named *MicroflowTutorial* to your solution.
18
18
3. Create a `MenuExtension` class.
19
-
4. Add a new class to the project and call it`CreateMicroflowsMenu.cs`.
20
-
5. Replace the code in the file with the code below.
19
+
4. Add a new class named`CreateMicroflowsMenu.cs`.
20
+
5. Replace the code in the file with the code below:
21
21
22
22
```csharp
23
23
usingMendix.StudioPro.ExtensionsAPI.UI.Menu;
@@ -43,11 +43,14 @@ You can download the example in this how-to in [this GitHub repository](https://
43
43
}
44
44
```
45
45
46
-
Asyoucansee, the `GetMenus` methodisoverriddentoaddyourownmenustoStudioPro. Theclass`CalculationsMicroflowCreator` (whichyouwilladdshortly) willbecalledfromtheactionofyourmenu. Youcanseethatthisclasshasbeeninjectedintheconstructorofyourmenuextension.
46
+
Thecodeoverridesthe `GetMenus` methodtoaddyourcustommenusintoStudioPro. The `CalculationsMicroflowCreator` class (added in the next step) is injected via the constructor and triggered by the menu action.
47
47
48
-
## Microflow Creator
48
+
## Add the Microflow Creator Class
49
49
50
-
Inthissection, youwilladdthe class `CalculationsMicroflowCreator.cs`, which will be injected into your menu extension so that it can be called from your menu action. Make sure to add the `Export` attribute to the class; otherwise, itwillnotbeinjectedintoyourmenuextension. The `ImportingConstructor` attributeontheconstructorisalsoveryimportant, asthisallowstheclassto receive any required services via dependency injection.
50
+
Add the `CalculationsMicroflowCreator.cs` classand follow the steps below:
@@ -67,7 +70,11 @@ class CalculationsMicroflowCreator(IMicroflowService microflowService, IMicroflo
67
70
}
68
71
```
69
72
70
-
This class contains one public method, which is the one called by your menu. The method `CreateMicroflows` requires the current app as the parameter. The `CreateMicroflowsMenu` extension has access to the `CurrentApp` property, so it will pass it to the method when calling it from the menu action. The `CurrentApp` property is the `IModel` for the app that is currently open in Studio Pro. Every extension that inherits the type `UIExtensionBase` (such as a `MenuBarExtension`) has access to the `CurrentApp` property and can interact and modify the model.
73
+
This class includes one public method called `CreateMicroflows`, which is triggered when you click your custom menu. It needs the current app as a parameter to work.
74
+
75
+
The `CreateMicroflowsMenu` extension can access the current app through the `CurrentApp` property. When the menu is clicked, it passes `CurrentApp` to `CreateMicroflows`.
76
+
77
+
The `CurrentApp` is the `IModel` that represents the app currently open in Studio Pro. Every extension that inherits from `UIExtensionBase` (like `MenuBarExtension`) has access to `CurrentApp`, which allows it to interact with and change the app's model.
71
78
72
79
Add the method as follows:
73
80
@@ -84,22 +91,32 @@ public void CreateMicroflows(IModel currentApp)
84
91
}
85
92
```
86
93
87
-
As you can see, the `CreateMicroflows` method starts a new transaction, by calling `currentApp.StartTransaction`, which is the only way an extension can modify the model of the app. If your class tried to create microflows outside of a transaction, an error will be thrown. For more information, see [Interact with the Model API Using C#](/apidocs-mxsdk/apidocs/interact-with-model-api-11/).
94
+
The `CreateMicroflows` method starts a new transaction by calling `currentApp.StartTransaction`, which is required to modify the model. If your class attempts to create microflows outside a transaction, it will result in an error. For more details, see [Interact with the Model API Using C#](/apidocs-mxsdk/apidocs/interact-with-model-api-11/).
95
+
96
+
Use `IMicroflowService` to create microflows. For more information, see [Create a Microflow and Add Activities Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-microflow-add-activities/). It requires:
88
97
89
-
`IMicroflowService` enables creating microflows. For details, see [Create a Microflow and Add Activities Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-microflow-add-activities/). It requires the current model (`IModel`), the containing module or folder inside a module (`IFolderBase`), a name, and an optional `MicroflowReturnValue`. The return value is actually used in the example, so you will see how to create one as well.
98
+
*`IModel` (the current mode),
99
+
*`IFolderBase` (module or folder)
100
+
* Microflow name
101
+
*`MicroflowReturnValue` (optional)
90
102
91
-
A microflow returns a value with `IMicroflowExpression`. This can be achieved by using your `IMicroflowExpressionService`, which returns an expression from a String input, and set that expression as the microflow's return value.
103
+
A microflow returns a value with `IMicroflowExpression`. This can be done by using `IMicroflowExpressionService`, which returns an expression from a string input, and sets the expression as the microflow's return value.
92
104
93
-
A very simple `MicroflowReturnValue` can be created as follows:
105
+
An example simple return value is seen below:
94
106
95
107
```csharp
96
108
newMicroflowReturnValue(DataType.Boolean, microflowExpressionService.CreateFromString("true or false"));
97
109
```
98
110
99
111
However, the example will have more complicated expressions, which use parameter names. These parameter names match the return values from called microflows.
100
-
This simple extension will create three microflows. Two of them will perform mathematical calculations (multiplication and addition) and each of them will return their result. The other microflow will call these two microflows in sequence, compute their two results (subtract the addition result from the multiplication result), and return true or false if the value is larger than 0.
101
112
102
-
The method `CreateMicroflowsInFolder` will create the two microflows and the return values. Add the method.
113
+
This extension creates three microflows:
114
+
115
+
1. Multiplication microflow – multiplies integers and returns the result
116
+
2. Addition microflow – adds decimals and returns the result
117
+
3. Main microflow – Calls the above two microflows in sequence, subtracts the addition result from the multiplication result, and returns `true` or `false` if the value is larger than 0.
118
+
119
+
Use the `CreateMicroflowsInFolder` method to create the two microflows and their return values:
To create a microflow which performs a multiplication between two input parameters (two numbers in this case), you can use the code below. As you can see, the String `multiplication1` and the String `multiplication2` match the parameters used in the expression for the return value. Note that for an expression, the dollar sign `$` must be put in front of the parameter name in order to be recognized as a variable input.
137
+
### Multiplication Microflow
121
138
122
-
You can also see that the `DataType` of both parameters is integer.
139
+
To create a microflow that performs multiplication between two input parameters, use the code below.
The strings `multiplication1` and `multiplication2` match the parameters used in the expression for the return value. Note that for an expression, the dollar sign `$` must be put in front of the parameter name in order to be recognized as a variable input.
163
+
164
+
You can also see that the `DataType` of both parameters is integer.
To create a microflow that performs an addition between two decimal values, you can use the code below. Just like the multiplication microflow example above, you can see that the String `addition1` and the String `addition2` match the parameters used in the expression for the return value. You can also see that their `DataType` is decimal.
168
+
### Addition Microflow
169
+
170
+
To create a microflow that performs addition between two decimal values, use the code below.
Like the multiplication microflow example above, the strings `addition1` and `addition2` match the parameters used in the expression for the return value. Their `DataType` is decimal.
Once a microflow is created, in order to enable this microflow to be called by other microflows, you need to add a call activity (`IActionActivity`). In the example, you have a method called `CreatMicroflowCallActivity` that can be used by both your multiplication and addition microflows.
197
+
## Create Microflow Activities That Call Java Actions
198
+
199
+
Once a microflow is created, you need to add a call activity (`IActionActivity`). In the example, you have a method called `CreatMicroflowCallActivity` that can be used by both your multiplication and addition microflows.
173
200
174
201
There are a few prerequisites that you must complete before a microflow can be called by another microflow. This method can be broken down into parts:
0 commit comments