Example – CSharp code

Estimated reading: 2 minutes 2090 views

Here’s a guide on how to implement your C# code within a workflow:

In the following example, I will demonstrate how to utilize the “InvokeCode” activity to invoke my custom C# code in the workflow. My custom C# code is designed to generate a password with 16 characters. 

Click here to download the 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. Choose the “Open Code Editor” option to provide the C sharp code. (Refer the attached code above).
5. 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.
6. First, create a variable.
7. Navigate to the “Variables” section and create a variable named “Secret_Key” with the “String” datatype. (Refer the below image)

8. Move to the activity and choose the “Arguments” option to add/ edit the arguments that are invoked to the code.
a. A pop-up labeled “Argument Panel” will appear on the screen.
b. Enter the “Name” as “Password” and in the “Value” field provide the variable as “Secret_Key”.
c. Ensure to set the “Direction” as “OUT” since we are retrieving the values from the code as output.
d. Click the save button. 
9. To pass this argument inside the code, again choose the “Edit Code” option.
a. At line number 10, the code will print the output in the log file. (Refer the below image)

b. Let’s modify this line to retrieve the output in the variable we created.
c. Enter the value as InvokeArguments.password = password.ToString();
d. To pass the argument values to the code, you must provide the value as InvokeArguments.argumentname.
12. Click the “Save” button.
13. Next, add a “WriteLog” activity to print the values of the variables called in the code.
 a. Enter the input string value as “Password: ” + Secret_Key.
 b. Choose the log level as “Info”. 
14. Save and execute the workflow.

Share this Doc

Example – CSharp code

Or copy link

CONTENTS