Using Custom JavaScript and C Code

This task describes how to insert code into a TruClient script. You can insert code into a pre-existing step as part of a step argument or insert steps that are completely comprised of external code (C or JavaScript).

Insert code into a step

You can insert JavaScript code into preexisting steps in the arguments fields of most steps. This allows you to perform multiple customizations.

Back to top

Insert code-only steps

You can insert steps comprised entirely of code into your script. To do so, select Toolbox > Miscellaneous and drag the Eval Javascript, Eval C, or Eval JS on Object icon to the desired location. The Eval JS on Object step runs the JavaScript code after the specified Object has loaded. We recommend avoiding Eval C and using JavaScript instead wherever possible. You can refer to this object as the variable "object" in the JavaScript code within the step.


The following code creates a variable called amount that generates a random number between 1 and 5. You can then use this variable in the argument fields of other steps.

var amount = Math.floor(Math.random() * 5) + 1;

Back to top

Edit multi-line JavaScript code

Click the JS icon in the element where you want to insert or edit multi-line JavaScript.

Do not use a return statement. The last line evaluated is the return value. In the example below, the value of the Text argument is "Testtask-"+datetime

Back to top

Set up commonly used JavaScript functions

You can set up commonly used functions in the JS-functions.js file.

For example:

* Returns a random integer between min (inclusive) and max (inclusive)
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;

and in a step you can set variables:

var ToMonth = getRandomInt(6,12);
var ToDayOfMonth = getRandomInt(1,30);

or you can directly use the functions from JS-functions.js file when setting an object value:

getRandomInt(6,12) + "/" + getRandomInt(1,30) + "/16" // random dates from 6/1/2016 to 12/30/2016

Back to top

See also: