Other functions

All database functions require an ID (connectionId) that represents the logical connection to be used. The ID is the fully qualified name of a previously configured database in the following format: Logical/nodeName. The value of nodeName is the path to the database connection. To determine this value, locate the database object in the Test Factory view and note the folder structure where it is located.
For more information, see Database resources, connections, and bindings.
Note: Functions can be written in Legacy Script Language or in ECMAScript. For details, see Scripts within tests and stubs. All the examples given in the following table are in Legacy, unless otherwise specified.
Table 1. Function description
Function Example Description
dbQuery(connectionId, query)
The project path of the logical database resource you want to query. For example, "Acct/JDBC/SQL". Note that the "Logical/" prefix is not used.
The SQL statement to run against the selected database.
dbQuery("Acct/JDBC/SQL","SELECT * FROM credits")
Runs a SQL query against a configured database, returning the value from the first column of the first row of the result set. The function is typically used to request singular elements of data.
dbUpdate(connectionId, updateSQL)
The full path of the logical database resource you want to update. For example, Logical/MyProject/Accounting/JDBC/SQL-Accounts.
The SQL statement to run against the selected database.
dbUpdate("Accounting/JDBC/SQL-Accounts","UPDATE Persons SET Acct='Savings' WHERE LastName='Taylor' AND FirstName='Robert'")
dbUpdate("Accounting/JDBC/SQL-Accounts", "UPDATE Persons SET Acct='Savings' WHERE LastName='Taylor' AND FirstName='Robert'")
Runs an update-based SQL statement against a configured database, returning the number of rows that are affected by the statement.
join(delimiter, expr, expr, ...)
Combines the listed arguments into a single string by using the specified delimiter. For example, join(;,2,3,4) returns 2;3;4. You can use the function to store a list of values into a single tag.
logToConsole(role, message)
The role for the log message, which must be Info, Warning, or Error. The role parameter is not case sensitive. The role defaults to Info if any other value is specified.
The message to log to the console, which can be any string.
logToConsole("Info","this is a log message")

This function writes a specified output message to the console. Logging an Error message gives the overall test a fail status, but subsequent test steps are executed as the logic of the test requires.

The number of Information, Warning, and Error messages generated by the logToConsole function are totaled in a "Logging summary" message at the end of the test.

lookupTD(dataSetPath,[keyColumn,matchValue,]* resultColumn,<defaultValue>)
The project path (string) to the test data set to search.
The column name to match against.
The value in keyColumn to find. Additional pairs of columns and values can be specified to create AND logic.
The column from which to take the result, in the row where the value is matched.
The value to return if no match is found.
Provides keyed access to a data set. This function works the same way as the Lookup Test Data test action, except that matching results are returned to the function rather than mapped to a tag.
If you have test data sets of differing type but with the same name, such as File and Database, they must be specified by including the proper extension, according to the following data set types:
Database data
Excel data
Directory data
File data
Returns the current time in the specified date and time pattern. For more information, see Formatting and parsing date-time patterns. The output of the function can be used in two ways:
  • In other actions, such as in a log action to be sent to the console
  • Stored for use by other actions within the test
Returns a null value, which you can use to set tag values or to compare to a database query result.
Note: Applies only to ECMAScript.
Using the keyword tags as a parameter, prints the complete list of tags with their values to the test console.
Prints the string literal or the value of the tag to the test console.
print("Override the default value with New value")
Print the value or the complete list of tags to the test console.
Replaces tags that are used in other tags with their value in the current tag store. The contents of the tag (by using the replaced values) can then be stored in a new tag.
For example, consider the following tags and their default values:
  • %%tag1%% = A
  • %%tag2%% = B
  • %%tag3%% = %%tag1%% comes before %%tag2%%
  • replaced = replaceTags(%%tag3%%)

The value of %%replaced%% is "A comes before B".

The name pattern is an optional regular expression used to match one or more tag names. If the pattern is omitted, all tags are reset.

It is not possible to use this function to reset global tag values as it is not clear what value to reset to. The tag's starting value might be inherited from the previous test, or from the default value.




Resets all tags that match a stated pattern to their default values. Use regular expressions to create the pattern that the tags must match.
  • The first example resets all tags.
  • The second example resets all tags that begin with the word stress followed by only two digits.
  • The third example resets all tags that contain the word stress followed by at least two digits.
  • The fourth example resets the tag with the name stress02.
  • The fifth example resets the tags with a name that matches the pattern stored in the tag %%variable%%.
settlementDate ("startDate", days <Int +/->, "holidayFilename" 
[, "dateFormat" <default="yyyyMMdd">])
The starting date, specified as a string value that contains a formatted date.
days <Int +/->
A positive or negative value (indicated with "+" or "-") that defines the number of days after or before startDate.
The full path to a simple text file that contains a list of dates to ignore, separated by the newline character. If the file pathname is not qualified, the default directory is the HCL OneTest API installation directory. All functions that can take a filename must include the full location of the file, which can be specified as a local or UNC path.
An optional argument that defines the format to be used for startDate, dates in holidayFilename, and the date that is returned by the function. The format "yyyyMMdd" is the default.
settlementDate ("20140101", +60, "UK_holidays.txt")
Determines a working date that is a defined number of days from a start date. The function counts working days only, ignoring weekends and holidays according to the local calendar. Holidays are configured by using a simple text file that contains a list of dates.
The name of an existing tag whose value is to be set.
setTag("mine", "new value");
mine="new value"
Replaces the contents of an existing tag with a function, expression, or constant specified by "value". You can also do this by using the store operation functionality from within the Function action. The specified tag must already exist.

Do not include beginning and ending percent signs (%%).

Reads and returns the contents of a text file in a specified location. The file contents can be stored in a tag for use in other phases of the test.

The full location of the file can be specified as a local or UNC path.

validateDTD(xml, [dtdURL_1, ..., dtdURL_n] )
validateXSD(xml, [schemaURL_1, ..., schemaURL_n] )
validateXSD( %%doc%%, file:///c:\Schemas\example.xsd )
Determine whether an XML document (xml) is valid in terms of the provided schemas (dtdURL or schemaURL).
The functions behave differently depending on context:
  • If called from within a function action, they return the textual output from the validation process.
  • If called from within a decision action, the output is merged into a boolean result so that an appropriate path can be chosen.
XMLdbQuery(connectionId, query)
  • connectionId- The full path of the logical database resource you want to query (for example, Logical/MyProject/Accounting/JDBC/SQL-Accounts).
  • query- The SQL statement to run against the selected database.
XMLdbQuery("Users/JDBC/SQL-People","SELECT person, age FROM users")
XMLdbQuery("Users/JDBC/SQL-People","SELECT person, age FROM users");
Runs a query-based SQL statement against a configured database. The result set of this query is then encoded as XML and provided as the return value from the function.
The XML fragment that is returned conforms to the following schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="resultSet">
    <xs:element name="columns">
       <xs:element maxOccurs="unbounded" name="column">
         <xs:attribute name="name" type="xs:string" use="required" />
         <xs:attribute name="type" type="xs:string" use="required" />
    <xs:element maxOccurs="unbounded" name="row">
       <xs:any minOccurs="0" />
   <xs:attribute name="rowCount" type="xs:decimal" use="required" />
The example shown returns the following output:
<?xml version="1.0" encoding="UTF-8"?>
<resultSet rowcount="2">
    <column name="person" type="string">
    <column name="age" type="number">
xpath(xml, xpath)


For example, (detailed previously).

xpath(srcData, "/resultSet/columns")
Returns the result of performing an XPath query (xpath) on some XML source that is to be validated (xml). you can get the same result by using the store operation functionality from within the Function action.

The example shown returns the number of rows that are provided in the output from the execution of an xmlDbQuery() function.

HCL OneTest API uses the XPATH 2.0 draft standard. Therefore, the fully qualified node name, including the namespace, must be used when matching nodes.

If attributes are included in the XML, the XML must be quoted and the quotes that surround the attribute must be escaped. The following example illustrates this requirement:
xpath("<a><b action=\"copy\"/></a>", "a/b")