Share this page

# TruClient functions and function libraries

This topic describes how to create TruClient functions. It also describes how to create a function library which enables you to use the functions locally, or share them for use in other scripts.

In this topic:

## Functions overview

A function is a reusable group of steps you define to perform a task. You store functions in libraries that can contain more than one function.

Note:

- Libraries replace the older method of keeping custom code in JS-functions.js (this file is still supported for backward compatibility).

- Recursive calls to functions are not allowed.

A library can be local or global:

- A local library can be accessed by the script that created it.

- A global library can be shared locally or on the network, and accessed by all TruClient scripts that can access the share location.

  Note: Global libraries are not included in the automatic backup and recovery process.

## Create a function

1. Select the Functions Libraries tab at the bottom of the TruClient Development window.

2. Select an existing library from the dropdown list or click the button from the Function toolbar to create a new library.

3. Click the button to create a new function. This inserts a new unspecified function.

4. Click the button to expand the function.

5. Define the step including function name and end event.

6. Define the function arguments using the Argument Editor. Give the arguments meaningful names so that when you are using the function, it is clear what value you need to specify.

7. Define the transaction using the Transaction Editor. For details, see Insert transactions.

## Reference a function argument within the function

To access the function arguments within the function, use the syntax `FuncArgs.<arg_name>`.

For example:

Note: This is relevant when using the JavaScript editor only.

## Create a function within a script

1. Highlight the steps in the script to include in the function. To select multiple steps, press CTRL.
2. Right-click the highlighted steps and select Group Into > New Function which opens the Create New Function dialog box.

3. To assign steps that contain arguments, expand the argument section, and insert the function `FuncArgs.<argument name>`.

   Tip: To insert JavaScript as the argument value, click the button to access the JavaScript editor.

## Create a global library

1. Select the Functions Libraries tab at the bottom of the TruClient Development window.

2. Select an existing library from the NewLib list.

3. Click the Export button to export the library to a location on your file directory as an xml file.

## Copy a test object between object repositories

The local object repository contains the object definitions for a script and the script's local library. A global object repository contains the object definitions for one global library. There are as many independent global object repositories as there are global libraries. If you copy and paste a step that contains a test object within one object repository, the new step is linked to the test object of the step you copied.

However, if you copy steps containing test objects between object repositories, you create new, independent test objects that point to the same UI element. These copies are not linked to each other. To keep these objects pointing to the same UI element:

- If you change or update one of the test objects in the local library or the script, you must update that object in the global library or libraries.
- If you change or update one of the test objects in a global library, you must update that object in the script or local library and in any other global library that contains the same object.

Examples of pasting between object repositories that create new test objects are:

- Copying from a script or local library to a global library.
- Copying from a global library to a script or local library.
- Copying between global libraries.

If you copy more than one step between object repositories, you create as many copies of the test object as there were in the steps you pasted. This applies even if you copy more than one step in a single paste operation.

## Use a function in a script

1. Click the Add Step button in the menu toolbar.

2. In the Functions tab, drag and drop Call Function to the correct location in your script.

3. Click the Call Function link to expand the function.

4. Specify the library and the function in the step section.

5. (Optional) Specify the arguments' values in the arguments section. For details, see Create a function within a script.

6. (Optional) Specify transactions in the transaction section. For details, see Insert transactions.

## Create New Function dialog box

This dialog box enables you to create new functions and assign functions to a library.

To create a new function, right-click the highlighted steps, and select Group Into > New Function.

UI Element | Description
--- | ---
Function name | Enables you to specify a function name.
Add to library | Select existing. Saves new function to an existing library. Create new. Saves new function to a new library.
Replace steps with function call | If selected, TruClient automatically inserts a call function in place of steps.

Note:

- When working with a global library, you can save changes to the library by clicking the Save Global Library button.

- If you save the library to a network location, other users can click the Import Library button to import the library.

- Click the Delete Library button to remove the library from the script. Global libraries are not deleted by this action.

- Click the Refresh function call arguments button to update the arguments when a function is modified; this also indicates if there is an issue with the arguments.

## See also

- Event handlers
- TruClient step arguments

https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 26.1-26.3 All View Local Help Center View Online Help Center Version: