JScript.NET

The JScript.NET action executes JScript.NET code authored by the user, allowing for powerful scripting capabilities within the RPA engine. This action supports setting and getting bot variables, as well as writing output to response variables.

Note: The Actions Quick Reference provides a complete list of actions that you can print for easy reference.

  1. On the Actions list, click Advanced and select JScript.NET.

  2. Select a Method

    • Code: This method compiles the content of the action and runs it. You can use Nintex Bot variables, tokens, and list lookups, which are not possible if you select the File method.

    • File: This method reads and compiles the content of the specified file and runs it. If you are working with a larger piece of code, using the File method with separate files may be easier. You cannot use Nintex Bot variables, tokens, and list lookups with this method.

  3. Determine how long to wait for the code to complete before proceeding with the Nintex Bot project and enter the number of seconds to wait in the Timeout field. By default, Nintex Bot will wait for 30 seconds before stopping the code by force. If no timeout is specified, then Nintex Bot will wait indefinitely for the code to complete.

  4. If you selected the Code method, enter your JScript.NET code to execute in the Code field. Nintex Bot will take the code you write and compile it in a temporary .exe file, execute the program, and delete it again.

  5. If you selected the File method, specify the path to the File that you want to execute. You can click the Magic Wand to use the Expression Builder.

  6. (Optional, but recommended) In the Save to field, specify the Nintex Bot variable in which you want to save the result output of the code. You can click the Magic Wand to use the Expression Builder.

    The result will be the output of any "Console.WriteLine" statements (also "Console.Write").

Example

Here is an example of a simpleJScript.NET program that prints a message. In this example, we will save the output in a variable. If you do not have any "Console.WriteLine" statements in your code and there are no errors, the output will be empty.

First, create a Nintex Bot variable called Output and write one line of code:

Console.WriteLine("Hello World!");

Capabilities

  • RPAEngine.SETVAR: Allows users to set a bot variable from within the JScript.NET code.

  • RPAEngine.GETVAR: Allows users to get a bot variable's value for use within the JScript.NET code.

  • Console.WriteLine: Writes the result to the response (Save to) variable set in the Action Builder.

Example Code Sections

Setting a Bot Variable

To set a bot variable from within your JScript.NET code, use the RPAEngine.SETVAR function. This function assigns a value to a specified bot variable.

// Example usage of setting a bot variable

var result = 15; // This is the value you want to set

// SET Bot variable to the result

RPAEngine.SETVAR("exampleResponse2", result);

 

Getting a Bot Variable

To retrieve the value of a bot variable for use within your JScript.NET code, use the RPAEngine.GETVAR function. This function fetches the value of a specified bot variable and assigns it to a local variable.

// Initialize a local variable to store the value

var tempCount = 0;

// GET Bot variable value

RPAEngine.GETVAR("exampleCount", tempCount);

// Now tempCount contains the value of the bot variable "exampleCount"

 

Writing the Result to the Console

To write the result or any output to the console (which also sets the response variable in the Action Builder), use the Console.WriteLine function. This outputs the specified message to the console.

// Example values

var number1 = 5;

var number2 = 10;

var result = number1 + number2;

// Writing the result string to the result variable (Save to variable) using Console.WriteLine

Console.WriteLine("The sum of " + number1 + " and " + number2 + " is: " + result);

 

Combined Example

Here is a complete example combining setting, getting, and writing operations:

// Function to calculate the sum of two numbers

function calculateSum(a, b) {

return a + b;

}

// Example usage of the function

var number1 = 5;

var number2 = 10;

var result = calculateSum(number1, number2);

// SET Bot variable to result of function

RPAEngine.SETVAR("exampleResponse2", result);

// GET Bot variable to use in code

var tempCount = 0;

RPAEngine.GETVAR("exampleCount", tempCount);

// Increment Count

tempCount++;

// SET Bot variable to new count

RPAEngine.SETVAR("exampleCount", tempCount);

// Writing the result string to the result variable (Save to variable) using Console.WriteLine

Console.WriteLine("The sum of " + number1 + " and " + number2 + " is: " + result);