Script Utilities
All scripts have access to a ScriptUtils class through the GetData arguments. All the commands fall under the Context method. This class contains the following utility functions:
Property or Function | Description |
DataRow DataRow { get ; } | It provides the functions to access the agent commands data defined under the Agent command. |
GlobalData GlobalData { get ; } | It provides the functions to access the agent’s Input Parameters data defined in the Agent command. |
Void ClearStorage() | Clears all the web browser cookies and javascript associated with the specified URL on the server. |
Bool Equals( object obj ) | It compares the contents and the contents being compared must be of object type. |
String GetConnectionString | Returns the underlying database connection. |
Int GetHashCode() | It returns a Hash code of an Integer value of 8 digits or numbers. Each time the script runs, it returns differently. |
Int GetRetryCount( string containerName) | It returns the number of counts the URL is retried using the Retry command. |
The above functions explained can be used in the following ways:
Example of DataRow Command:
public string GetData(RunContext context)
{
return "Product: " + context.DataRow.GetString("Product");
}
The context
class serves as a container for various methods & classes, including the DataRow
class. The DataRow
class provides access to the data associated with commands defined within the Agent Command. By utilizing the GetString
function within the DataRow
class, you can retrieve the content of the 'Product' command.
Example of GlobalData Command:
public string GetData(RunContext context)
{
return "Password: " + context.GlobalData.GetString("Password");
}
The GlobalData
class, a member of the context class, provides access to the data associated with input parameters defined in the Agent Command. The GetString
function within the GlobalData
class can be used to retrieve the content of the 'Password' command.
Example of ClearStorage Command:
public string GetData(RunContext context)
{
context.ClearStorage();
return "";
}
The ClearStorage
method is used to remove all web browser cookies and JavaScript associated with a specified URL on the parent command from the server. This method does not return any content, so its call is typically not assigned to a variable or returned.
Example of GetConnectionString Command:
public string GetData(RunContext context)
{
return context.GetConnectionString("runtime");
}
The GetConnectionString
method returns the connection string to the SQLite database associated with the agent on the server, enabling you to execute SQL queries against that database.
Example of GetHashCode Command:
public string GetData(RunContext context)
{
return context.GetHashCode().ToString();
}
The GetHashCode
method generates a unique, eight-digit integer hash code. This hash code changes each time the script is executed. To convert the integer value to a string, we use the ToString()
method.
Example of GetRetryCount Command:
public string GetData(RunContext context)
{
return context.GetRetryCount().ToString();
}
The GetRetryCount
method tracks the number of times the Retry
command has been used to retry a specific command. To effectively utilize the GetRetryCount
method, it should be placed within the loop of the Retry
command. Note that the Error Handling
option in the command's Options
property does not function with the GetRetryCount
command. Instead, it should be defined between the command to be retried and the Retry
command. Finally, the ToString()
method can be used to convert the integer value returned by GetRetryCount
into a string.