Storing and retrieving variable values

You can use the getValue() and setValue() methods to store and retrieve values in variables. Depending on the storage location that you specify, variables can be shared among tests, or stored locally in the current test.

The Javadoc for the test execution services interfaces and classes can be accessed from the product by clicking Help > Help Contents > IBM Rational Performance Tester API Reference.

You can use the getValue() and setValue() methods to store multiple values in variables in one custom code call. You can then create substitutions from variables instead of from multiple custom code elements.

For example, assume that a response contains three values: id, book title, and price. You can read all three values from the response, and then use custom code to set the variables id, title, and price. You can then substitute the values from the three variables as needed in the test, instead of having to write custom code for each variable.

Note: The storage location passed to the method must match the storage location used when declaring the variable.
package customcode;

import com.ibm.rational.test.lt.kernel.IDataArea;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;

/**
     * For Javadoc information on the ICustomCode2 and ITestExecutionServices interfaces,
     * see the 'Extending test execution with custom code' help topic.
     */

/**
 * @author IBM Custom Code Samples
 */

    public String exec(ITestExecutionServices tes, String[] args) {
        
        tes.getValue("myVar", tes.STORAGE_USER);  // This retrieves a value from a test for the variable called myVar. The storage area is shared between tests.
        tes.getValue("myLocalVar", tes.STORAGE_LOCAL);  // This variable is stored locally, per test.
        
        tes.setValue("myVar", tes.STORAGE_USER, "myNewValue");  // Change the value of the variable myVar, which is shared between tests, to myNewValue.
        tes.setValue("myLocalVar", tes.STORAGE_LOCAL, "myLocalNewVar");  // Change the value of the local variable to myLocalNewVar.
        return null;
    }