Executing Your Own Classes from a Library 
The library allows you to store your RedwoodScript code for use in SAP CPS, in one or multiple triggers, for example, or in Redwood Expression Language.
You can write your own code directly in your library or add jar files to your library. RedwoodScript code in a library must always be in Full mode, that is start with package com.redwood.scheduler.custom.... This code can then be accessed from triggers, actions, job definitions, period functions, and Redwood Expression Language.
Note
Custom library names must always start with Custom_ or you will not be able to save the library.
A logger is an object that allows you to write log messages. Loggers have a category and a level. The category is the source of the message, and is arranged hierarchically. All loggers related to SAP CPS are in the category com.redwood., under which there are many more sub-categories (and sub-sub-categories and so on). Loggers also have a level, this controls the amount of information that is logged from a particular source. The levels (in order of most to least important) are:
FATAL - messages that will cause an immediate issue for the system or important customer functionality, that require human intervention to resolve.
ERROR - errors that only effect part of the system (eg. a job failing or a file not being present)
WARN - potential errors or misconfiguration.
INFO - informational messages, generally about progress in a long running task.
DEBUG - detailed information about system progress.
The logger object has two methods for each level, one that takes a message, and another that takes a message and a Throwable object (an exception).
Logger log = ...;
log.debug("Some information useful to developers is " + someVariableName);
log.info("Finished Pass 2/3");
try
{
...
}
catch (IOException ioe)
{
log.error("Error accessing file", ioe);
throw ioe;
}
To use your methods from within RedwoodScript, you first need to set the library containing your code on the object, you can then use your code using one of the following:
specifying <package_name>.<class_name>.<method_name>
import your class using the following import statement import <package_name>.<class_name>; and use <class_name>.<method_name>
Note
You should not use the jcs prefix in the names of your methods, as this prefix is reserved for the system.
You can use your methods in Redwood Expression Language throughout the product by specifying REL Entry Points with the following information:
Name - the name of the method to be used in Redwood Expression Language
FQ Class Name - the fully qualified class name
Method Signature - the method syntax
Note
You should not mix code in a same class that is to be used in Redwood Expression Language and RedwoodScript. See Mixing REL and RS Code in a Library for more information.
Note
You should not use the jcs prefix in the names of your methods, as this prefix is reserved for the system.
It is not recommended to persist a session in your library code that you intend to use in Redwood Expression Language, as it can have side-effects. The behavior or side-effects might even change from one release to the next without prior notice.
Persisting a session in your library code used for RedwoodScript may have side effects as well, especially when the code is used in triggers, job actions, or import rule set actions. It is strongly recommended not to persist a session in your library code if it is used in triggers, job actions, or import rule set actions.
You may persist a session in your library code when it is used by alert escalations, alert sources, or email alert gateways and none of the previously mentioned objects.
Libraries support the following actions:
Action |
Description |
Import JAR |
Import the code of a JAR file into the library |
Export |
Export the library into a CAR file |
Edit |
Edit the library |
Edit Security |
Edit the security of the library |
Delete |
Delete the library |
Duplicate |
Make a copy of the library to create a similar one |
Expand All |
Expand all libraries in the current filter |
New |
Create a new library |
Filter > New Filter |
Create a new library filter |
Filter > Edit Filter |
Edit current library filter |
Filter > Delete |
Delete current library filter |
You can search for libraries using filters and the Search Libraries box on the Libraries tab. This box is known as the intelliSearch box and located under your username on the top right-hand side of the user interface. Filters allow you to specify a list of objects with static criteria. IntelliSearch allows you to specify complex queries in a simple way using prefixes. Prefixes are used to specify which property you are searching in and have short and long syntaxes. For example, if you want to display all libraries with the term trigger in the comment, you would use the search criteria as follows:
c:trigger
You can search more than one property, as follows:
c:trigger n:JV
Note
No spaces should be entered before or after the colon (:).
See the Advanced Object Search for more information.
The following table illustrates the available prefixes for libraries:
Prefixes |
Description |
n, name |
searches the name property |
c, com, comment |
searches the comment property |
d, desc, description |
searches the description property |
a, app, application |
searches the application property |
You can only delete libraries when no other objects relate to them. For example, if there are job definitions that use the library, the library cannot be deleted until all job definitions that use it have been modified. You can see all job definitions that relate to the library in Related Objects in the lower detail pane and on the show page.
The table in related objects contains three columns:
Type - the type of object with a link to it
Related Object - the name of the object with a link to it
Used As - objects can sometimes be used in different roles
Privilege |
Description |
Library.Create |
Create librarys |
Library.Delete |
Delete librarys |
Library.Edit |
Edit librarys |
Library.View |
Access librarys |
You can grant privileges on two levels, Access and Admin; a privilege granted on Admin level allows the grantee to grant the privilege to other users. These privileges can be granted system-wide, per partition or isolation group.
If you have the security module, which requires the Module.Security license key, you have an additional Security tab on the library. It allows you to specify which users can access, edit, and delete the library.
Create you own package in the custom library
Navigate to .
Choose Edit from the context menu of the library.
Choose the Source tab, choose New and enter your code.
Choose Save to save your newly added package.
Choose the REL Entry Points tab and fill in the following information:
Name - the desired name of the method, the name should remind others of what the method does.
FQ Class Name - the fully qualified name of the class, <package_name>.<class_name>.
Method Signature - the signature of the method, e.g. its name in your code and the types of arguments that should be provided.
Add a jar file to the library
Navigate to .
Choose Add Jar from the context menu of the library.
In the Import Jar File Into Library make sure the Library Name is correct and navigate to the jar file. The jar file needs to be accessible to the system where SAP CPS is running.
Choose Send and wait until the jar file has been loaded. The System_Import_JarFile job definition gets submitted automatically to upload the jar file, if this job fails, the jar file has not been added. Please monitor the job and inspect the stderr and stdout files for more information.
In this example, one class is used for both RedwoodScript and Redwood Expression Language. This is for illustration purposes only to show you how to access your methods from both and should not be done in a production environment. Always keep methods for RedwoodScript and Redwood Expression Language in different classes.
Navigate to .
Choose Edit from the context menu of the Custom library.
Choose the Source tab, choose New and enter the code under the Example Code section.
Choose Save and choose the REL Entry Points tab and fill in the information under the REL Entry Points section:
// Example code to illustrate
package masalanCustomString;
public class concat
{
public static String concatString(String str1, String str2)
{
if (str1 == null && str2==null ) return "null";
return str1.concat(str2);
}
}
Name - concatenate
FQ Class Name - masalanCustomString.concat
Method Sinature - concatString(String,String)
In a job parameter:
=Custom.concatenate('Masalan ', 'Inc.')
You can also concatenate strings from parameters. If you do not make it a runtime parameter, however, it will only concatenate the default values of the parameters and not the values entered at submit time.
The following example was used in a job definition with three parameters, the first two had a Display Order of 0 and 1, respectively the third had a Display order of 99. The display order attribute defines the order at which parameters are displayed in the submit wizard as well as the evaluation sequence.
=Custom.concatenate(parameters.param1, parameters.param2)
In a job definition
Create a RedwoodScript job definition, choose RedwoodScript as job definition type and the library you added the above code to as library.
Give the job definition a name on the Job Definition tab.
On the source tab enter the following code:
{
jcsOut.println(masalanCustomString.concat.concatString(Param1, Param2));
}
An alternative, is to import the class, so you do not have to specify the package name every time:
import masalanCustomString.concat;
{
jcsOut.println(concat.concatString(Param1, Param2));
}