UiPath.Core.Activities.InvokeCode
Synchronously invokes VB.NET or C# code, optionally passing it a list of input arguments. This activity can also return out arguments to the caller workflow.
Note:
The assemblies referenced by your code need to be added into the Imports panel in order to function. You can find more info here.
Important!
Due to internal changes, this activity will no longer be visible in the Favorites list when upgrading to v20.4 or newer, if it was added to the Favorites list with a v19.4 or older version of UiPath.System.Activities.
Properties
Input
- Arguments - The parameters that can be passed to the code that is invoked.
- Code - The code that is to be invoked. This field supports only strings and
String
variables. - Language - A drop-down menu that specifies what language the invoked code is written in. The available options are VBNet and CSharp.
Common
- DisplayName - The display name of the activity.
- ContinueOnError - Specifies if the automation should continue even when the activity throws an error. This field only supports Boolean values (True, False). The default value is False. As a result, if the field is blank and an error is thrown, the execution of the project stops. If the value is set to True, the execution of the project continues regardless of any error.
Note:
If this activity is included in Try Catch and the value of the ContinueOnError property is True, no error is caught when the project is executed.
Misc
- Private - If selected, the values of variables and arguments are no longer logged at Verbose level.
Example of Using the Invoke Code Activity
The Invoke Code activity is used for directly calling vb.net
code from the UiPath platform. Using this activity you can specify exactly what code to be executed and what arguments to be passed to and from the activity.
This is how the automation process can be built:
- Open Studio and create a new Process.
- Drag a Sequence to the Workflow Designer.
- Create the following variables:
Variable Name | Variable Type | Default Value |
---|---|---|
| String | |
| Int32 |
- Drag an Assign activity inside the sequence container.
- Add the variable
ExampleInArgument
in the To field and the expression"Example for In Arguments"
in the Value field.
- Add the variable
- Add an Invoke Code activity below the Assign activity.
- Select the Edit Code button for introducing the desired code.
- Type the code in the Code Editor window. For this example we have added a simple code that writes a string on the screen. Here is the code we have used:
Dim TextToWrite As String
TextToWrite = "Example"
Console.WriteLine(TextToWrite)
- Select the OK button to close the Code Editor window.
- Select the Edit Arguments button and create the following arguments:
Argument Name | Argument Direction | Argument Type | Argument Value |
---|---|---|---|
| In | String |
|
| Out | Int32 |
|
- Select the OK button to close the Invoked code arguments window.
- Place a Write Line activity under the Invoke Code activity.
- Add the expression
OutValue.ToString
in the Text field.
- Add the expression
- Run the process. The robot displays in the Output panel the code and arguments specified by you in the Invoke Code activity.
Updated 8 months ago