Show TOC

Procedure documentationExecuting Your Own Classes from a Library Locate this document in the navigation structure

 

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 Note

Custom library names must always start with Custom_ or you will not be able to save the library.

End of the note.
Using Loggers in Libraries

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;

}

Accessing Libraries in RedwoodScript

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 Note

You should not use the jcs prefix in the names of your methods, as this prefix is reserved for the system.

End of the note.
Accessing Libraries in Redwood Expression Language

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 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.

End of the note.

Note Note

You should not use the jcs prefix in the names of your methods, as this prefix is reserved for the system.

End of the note.
Persisting Sessions in Libraries

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.

Actions

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

Finding Libraries

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 Note

No spaces should be entered before or after the colon (:).

End of the note.

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

Deleting Libraries

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

Security

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.

Procedure

Create you own package in the custom library

  1. Navigate to   Scripting → Libraries  .

  2. Choose Edit from the context menu of the library.

  3. Choose the Source tab, choose New and enter your code.

  4. Choose Save to save your newly added package.

  5. Choose the REL Entry Points tab and fill in the following information:

    1. Name - the desired name of the method, the name should remind others of what the method does.

    2. FQ Class Name - the fully qualified name of the class, <package_name>.<class_name>.

    3. 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

  1. Navigate to   Scripting → Libraries  .

  2. Choose Add Jar from the context menu of the library.

  3. 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.

  4. 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.

Example

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.

  1. Navigate to   Scripting → Libraries  .

  2. Choose Edit from the context menu of the Custom library.

  3. Choose the Source tab, choose New and enter the code under the Example Code section.

  4. Choose Save and choose the REL Entry Points tab and fill in the information under the REL Entry Points section:

Example Code

// 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);

}

}

REL Entry Points
  • Name - concatenate

  • FQ Class Name - masalanCustomString.concat

  • Method Sinature - concatString(String,String)

Use in Redwood Expression Language

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)

Use in RedwoodScript

In a job definition

  1. Create a RedwoodScript job definition, choose RedwoodScript as job definition type and the library you added the above code to as library.

  2. Give the job definition a name on the Job Definition tab.

  3. 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));

}