Scripting in the Shell
The Shell allows you to access the Repository directly with a scripting language. You can use it to automate repetitive tasks, for example, submit 10 processes. It can also be used to write or debug your RedwoodScript or Redwood Expression Language code as well.
RedwoodScript Version
By default, RedwoodScript is based on Java 11; you set the /configuration/javatoolkit/SourceVersion
and /configuration/javatoolkit/TargetVersion
registry entries to your desired version and can use all the features of the version you specify.
Setting Locales
By default, the scripting locale is set to English, you can change it to German, for example, using the following code:
importPackage(java.util);
jcsSession.setLocale(Locale.GERMAN);
Setting the Return Code
The jcsShell.setReturnCode(int)
method is used to set the return code of the script. You throw an exception if you want to terminate processing; the last effective call to jcsShell.setReturnCode()
will set the return code. This is used by the api-tool.jar
and jtool script
.
Procedure
- Navigate to "Scripting > Shell".
- Enter your code in the lower pane.
- Choose Submit Command.
- The result of your code will be printed in the upper pane.
- Close the tab when you are finished.
Example
To submit one process without parameters, you could use the following code:
{
// Get the JobDefinition object
JobDefinition jDefinition = jcsSession.getJobDefinitionByName("System_Sleep");
// Create a process object
Job process = jDefinition.prepare();
// To submit the process, you need to commit changes to the database
jcsSession.persist();
}
To submit 10 processes without setting any parameters, you could use the following code:
{
// Get the JobDefinition object
JobDefinition jDefinition = jcsSession.getJobDefinitionByName("System_Sleep");
for (int i = 0; i < 10; i++)
{
// Create a process object
jDefinition.prepare();
}
// To submit the processes, you need to commit changes to the database
jcsSession.persist();
}