Example – VB.NET Code

Estimated reading: 3 minutes 2121 views

Here’s a guide on how to implement your VB.NET code within a workflow:

In the following example, I will demonstrate how to utilize the “InvokeCode” activity to invoke my custom VB.NET code in the workflow. Within my custom VB.NET code, I have designed it to execute a straightforward calculation using the default numbers provided within it.

Click here to refer the below attached code.

1. Create a new solution.
2. Install the “Core Activities” from the Manage Features.
3. Drag and drop the “InvokeCode” activity into the workflow and set it as the start node.
a. This activity helps you integrate custom code into your automation workflow. 
4. Navigate to the “Language” in the properties section to choose the preferred language that we are going to perform.
a. Here select the value as “VB Net”. 
5. Choose the “Open Code Editor” option to provide the VB code in the activity. 
6. A window labeled “Invoke Code” will open.
a. Enter the custom code here. Refer to the attached VB.NET code.
b. Click the save button.
7. Before proceeding with the execution, let’s create a variable to retrieve the output from the code.
a. This variable will be passed to an argument, which will be used in the code to retrieve the output.
8. First, create a variable.
a. Navigate to the “Variables” section and create a variable named “TOTALAdd” with the “Int32” as datatype. 
9. Move to the activity and choose the “Arguments” button.
a. A pop-up labeled “Argument Panel” will appear on the screen.
b. Enter the “Name” as “Add” and in the “Value” field provide the variable as “TOTALAdd”.
c. Ensure to set the “Direction” as “OUT” since we are retrieving the values from the code as output.
d. Click the save button. 
10. To pass this argument inside the code, again choose the “Edit Code” option.
a. At line number 38, the code will print the output to the console log file. (Refer the below image)

b. Let’s modify this line to retrieve the output in the variable.
c. Enter the value as InvokeArguments.ADD = calculator.Add(num1, num2)
d. To pass the argument values to the code, you must provide the value as InvokeArguments.variablename. 
e. Here the “num1 and num2” values are hardcoded as (10 and 5) in the code already.
11. Click the “Save” button.
12. You can also follow the same steps to create variables to view the subtraction, multiplication, and division outputs in the variables.
13. Next, add a “WriteLog” activity to print the values of the variables called in the code.
a. Enter the input string value as “Addition Result: ” + TOTALAdd.ToString.
b. Choose the log level as “Info”. 
14. Save and execute the workflow.

Share this Doc

Example – VB.NET Code

Or copy link

CONTENTS