UiPath Activities Guide

Invoke Code

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.

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:

  1. Open Studio and create a new Process.
  2. Drag a Sequence to the Workflow Designer.
    • Create the following variables:
Variable Name
Variable Type
Default Value

ExampleInArgument

String

-

OutValue

Int32

-

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

ExampleInArgument

In

String

ExampleInArgument

ExampleOutArgument

Out

Int32

OutValue

  • Select the OK button to close the Invoked code arguments window.
    1. Place a Write Line activity under the Invoke Code activity.
  • Add the expression OutValue.ToString in the Text field.
    1. Run the process. The robot displays in the Output panel the code and arguments specified by you in the Invoke Code activity.

Download example


Invoke Code


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.