Working with command results in embedded mode

The EmbeddedScript method getResult() returns the result of the last command that was executed.

There are five types of Result supported by EmbeddedScript.

In order to cast a result to its specific type, check the result object to determine which class it is, or call getType(). While the documentation indicates the type of result returned for each command, it is recommended to confirm that the type is the correct instance before using it.

Using instanceof to check the type:

script.execute(list subscriptions);
Result result = script.getResult();
if (result instanceof ResultStringTable)
{
   ...
}

Using getType() to check the type:

script.execute(list subscriptions);
Result result = script.getResult();
switch (result.getType())
{
case Result.TABLE:
   ...
   break;
}

The key methods for each of the result types are as follows:

  • ResultNull for commands with no output.
    String
    toString()

    Returns an empty string

  • ResultStringKeyValues for commands that return a collection of string-based key-value pairs.
    String[]
    getKeys()
    Returns an array containing the keys in the result.
    String[]
    getNames()
    Returns the column names for the result.
    int
    getRowCount()
    Returns the number of keys in the result.
    String
    getValue(String key)
    Returns the value for a given key, or null if the key cannot be found.
    String
    toString()
    Returns a formatted text representation of the result.
  • ResultStringList for commands that return a list of strings.
    int
    getRowCount()
    Returns the number of strings in the result.
    String
    getValueAt(int row) throws IndexOutOfBoundsException
    Returns the value for a row index. Row indexes start from zero.
    String
    toString()
    Returns a formatted text representation of the result.
  • ResultStringTable for commands that return a table of records.
    int
    getColumnCount()
    Returns the number of columns in the table.
    String
    getColumnAt(int column) throws IndexOutOfBoundsException
    Returns the name of a column for the column index. Column indexes start from zero.
    int
    getRowCount()
    Returns the number of rows in the result.
    String
    getValueAt(int row, int column) throws ArrayIndexOutOfBoundsException
    Returns the value for a row and column index. Row indexes start from zero. Column indexes start from zero.
    String
    getValueAt(int row, String columnName) throws ArrayIndexOutOfBoundsException
    Returns the value for a row and named column. Row indexes start from zero. Returns null if no value is found.
    int rowCount = result.getRowCount();
    for (int row = 0; row < rowCount; row++)
    {
       String value = result.getValueAt(row, DATASTORE);
       …
    }
    int
    lookupRow(String lookupColumnName, String lookupValue)
    Returns the row index where the named lookup column contains the given lookup value.
    int row = result.lookupRow(LASTNAME, SMITH);
    String firstName = result.getValueAt(row, FIRSTNAME); 
    String middleName = result.getValueAt(row, MIDDLENAME);
    String
    lookupValue(String lookupColumnName, String keyColumnName, String keyValue)
    Returns the string value in the named lookup column where the named key column contains a key value.
    String firstName = result.lookupValue(FIRSTNAME, LASTNAME, 
    	SMITH);
    String middleName = result.lookupValue(MIDDLENAME, LASTNAME, 
    	SMITH);
    String
    toString()
    Returns a formatted text representation of the result.
  • ResultValue for commands that return a string value.
    String
    getValue()
    Returns the value.
    String
    toString()
    Returns a formatted text representation of the result.

The results for a command may contain elements that are translated. For example, an application run in Japanese will display column names, keys, and possibly values in Japanese. Applications written using EmbeddedScript must account for language differences, if those applications are run in multiple languages.