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-10/extensibility-api/csharp/extensibility-api-howtos/create-microflows-calculations.md
+71-37Lines changed: 71 additions & 37 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
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-10/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 following:
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-10/).
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-10/).
88
95
89
-
`IMicroflowService`enables creating microflows. For details, see [Create a Microflow and Add Activities Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-10/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.
96
+
Use`IMicroflowService`to create microflows. For more information, see [Create a Microflow and Add Activities Using C#](/apidocs-mxsdk/apidocs/csharp-extensibility-api-10/create-microflow-add-activities/). It requires:
90
97
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.
98
+
*`IModel` (the current mode)
99
+
*`IFolderBase` (module or folder)
100
+
* Microflow name
101
+
*`MicroflowReturnValue` (optional)
92
102
93
-
A very simple `MicroflowReturnValue` can be created as follows:
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.
104
+
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 Call Activities
198
+
199
+
After you create a microflow, you need to add a call activity (`IActionActivity`) so it can be used by other microflows. In the example, there is a method called `CreatMicroflowCallActivity` that works for both your multiplication and addition microflows.
173
200
174
-
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:
201
+
Before one microflow can call another, you need to complete some prerequisites. This method can be broken down into parts:
In order to create `IActionActivity`, `IMicroflowCallAction` must also be created, and set as the `Action` property of the `IActionActivity`.
213
+
1. Create `IActionActivity`. This is the activity that will call another microflow.
214
+
2. Create `IMicroflowCallAction` and set it as the `Action` property of the `IActionActivity`.
215
+
3. Create `IMicroflowCall` and set as the `MicroflowCall` property of the `IMicroflowCallAction`.
216
+
4. Set `QualifiedName` of the microflow you want to call as the `Microflow` property of the `MicroflowCall` object.
217
+
5. Set the `OutputVariableName` on `IActionActivity` so the calling microflow can use the result returned by the called microflow.
187
218
188
-
Then, for `IMicroflowCallAction`, `IMicroflowCall` must also be created and set as the `MicroflowCall` property of the `IMicroflowCallAction`.
219
+
## Passing Parameters to Called Microflows
189
220
190
-
Next, `QualifiedName` of the microflow, which is to be called by this activity, must be set as the `Microflow` property of the `MicroflowCall` object.
191
-
192
-
Finally, you can set `OutputVariableName` on `IActionActivity`, which is what the calling microflow will read from the called microflow.
193
-
194
-
## Passing Parameters
195
-
196
-
It is also possible to pass a set of parameters to the action activity, which will be the inputs for the called microflow. This set of parameters is a simple `Tuple` of a name and an expression. In the example, these parameters are the two integers for the multiplication microflow and the two decimals for the addition microflow.
221
+
You can pass parameters to the action activity, which will be the input for the called microflow. This set of parameters is a `Tuple` of a name and an expression. In the example, these parameters are the two integers for the multiplication microflow and the two decimals for the addition microflow.
To create a call activity for your multiplication and addition microflows, you can use something like the code below. As you can see, the parameter names for the activity match the parameter name from the microflow and their values are also passed in for integers and decimals.
263
+
To create a call activity for your multiplication and addition microflows, use code similar to the following:
As you can see, the parameter names for the activity match the parameter name from the microflow. Their values are passed in for integers and decimals.
Outside of this calculation examples, you might want to create a microflow activity that calls a Java action file. See below for how to add an activity, and action and a call to the microflow to achieve that. Same as in the previous examples, you have to do this inside a transaction (`IModel.StartTransaction`).
285
+
You can create a microflow activity that calls a Java Action. This must be done inside a transaction (`IModel.StartTransaction`).
259
286
260
-
First, create an `IActionActivity`, just like the calculation example above, but then, its `Action` property will have the type `IJavaActionCallAction` instead of `IMicroflowCallAction`. This `IJavaActionCallAction` will need to know which `IJavaAction` is linked to. You can achieve this by setting the property `JavaAction` on the `IJavaActionCallAction` object to the `IQualifiedName` of the `IJavaAction`. If you are creating a brand new `IJavaAction`, it is important to add it to the module before accessing its `IQualifiedName`. If you have `IJavaAction` already, and you want to set up a call for that one, find it in the app and pass along its `IQualifiedName`. See below for an example.
287
+
1. Start a transaction using `IModel.StartTransaction`.
288
+
2. Create an `IActionActivity`.
289
+
3. Set the `Action` property to `IJavaActionCallAction`.
290
+
4. Link `IJavaActionCallAction` to the `IJavaAction`.
291
+
5. Set the `JavaAction` property to the `IQualifiedName` of the `IJavaAction`.
292
+
6. For `IJavaAction`:
293
+
1. For a new `IJavaAction` – add it to the module. Only access its `IQualifiedName` after it has been added.
294
+
2. For an existing `IJavaAction` – find it in the app and pass its `IQualifiedName` to the `IJavaAction` property of `IJavaActionCallAction`.
@@ -283,7 +317,7 @@ public void CreateMicroflowAndJavaAction(IModule module, IModel currentApp)
283
317
}
284
318
```
285
319
286
-
If you already have a Java action file that you previously created, simply pass its `IQualifiedName` to the Java action. You will need to query the model in order to retrieve the actual object. You can do so as follows:
320
+
If you already previously created a Java action file, you can pass its `IQualifiedName` to the Java action. You will need to query the model to retrieve the actual object. You can do so as follows:
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
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ You can download the example in this how-to from [this GitHub repository](https:
16
16
1. Open the project you created when following [Create a Menu Extension](/apidocs-mxsdk/apidocs/csharp-extensibility-api-11/create-menu-extension/).
17
17
2. Add a new folder named *MicroflowTutorial* to your solution.
18
18
3. Create a `MenuExtension` class.
19
-
4. Add a new class named `CreateMicroflowsMenu.cs`.
19
+
4. Add a new class named *CreateMicroflowsMenu.cs*.
20
20
5. Replace the code in the file with the code below:
0 commit comments