MicroStrategy ONE

Using Java in Command Manager procedures

Java is a simple yet powerful programming language that is widely used in the software industry. Java can be integrated with Command Manager to automate repetitive tasks such as creating multiple users, or recursively listing all the folders in a project. Java is supported in Command Manager out-of-the-box; no additional software must be installed to execute Java commands.

To include Java in a Command Manager script, you write a procedure containing the Java code, and execute the procedure from a Command Manager script. Java cannot be included directly in a Command Manager script. In addition, Java is only supported in procedures, and procedures are only supported with project sources. Java commands cannot be used in scripts to be executed against a Narrowcast Server metadata.

Never use the System.exit command to exit a procedure. This command terminates the entire Command Manager process.

Command Manager provides two methods that can be used by Java scripts to execute Command Manager commands:

  • execute runs any Command Manager command. It returns an exit code.

  • executeCapture runs any Command Manager command and returns the results (if the command is a LIST statement) in a ResultSet object. This enables you to use the results elsewhere in the procedure.

Command Manager also provides two additional objects:

  • ErrorHandler stores information about any errors the execute and executeCapture commands encounter.

  • ResultSet provides the results from a Command Manager command that was executed from the executeCapture command. This object behaves like a standard ResultSet object in Java: you can iterate through the results and retrieve individual ResultCells, which can then be used to extract properties of the results. For information about retrieving the information from the ResultSet object, see Retrieving information from ResultSet objects.

For detailed syntax information on these commands, including examples, see Procedures and Java syntax. For examples of how to incorporate Java syntax into Command Manager procedures, see the Sample Procedures (found in the Choose Outline dialog box).

The script coloring feature of Command Manager only affects Command Manager statements. Java statements in procedures are not color-coded based on syntax, regardless of the setting of the Enable Text Coloring option.

Related Topics

Retrieving information from ResultSet objects

Exit codes for Java syntax in procedures

Procedures and Java syntax

Editing a script

Executing a script