This section summarizes the global functions that are neither log and error functions nor predefined scripts.
checkUserDNs(arrayOfUserDNs)
Verifies that all the DNs defined in the arrayOfUserDNs are valid and exist in the corporate directory. Return true if all the DNs are valid (or if the array is empty) otherwise returns false.
Example:.
var dnArray = new Array( "uid=sijacic, o=mcom.com",
"uid=atam, o=mcom.com",
"uid=souvik, o=mcom.com",
"uid=michal, o=mcom.com",
"uid=raghavan, o=mcom.com" );
// Check to see if all of the DNs are valid
if( checkUserDNs( dnArray ) )
java.lang.System.out.println( "All DNs are valid" );
else
java.lang.System.out.println( "One of the DNs is not valid" );
ejbLookup(jndiName)
Looks up an EJB that can be found under the given JNDI name. If no EJB exists under this name, an EJB exception, javax.naming.NamingException, is thrown. PAE handles this exception by moving the process instance into the designated Exception Manager node.
If the bean can be found under the given JNDI name, the home interface of that bean is returned. The home interface is used to create new instance of the EJB or find existing instnaces of the given EJB. The definition of the home interface is completely application-dependent; it typically consists of several create() and finder() methods. This function call is equivalent to the getJndiNamingContext().lookup(jndiName) function call.
Example:.
var home = ejbLookup("Netscape/CreditCardServer");
// Create a credit card server that can do card authorizations.
var creditCardServer = home.create ( "mastercard" );
evaluateTemplate(templateName)
Used primarily in email notifications, but can be used for any template-like evaluation.
For email notifications, use evaluateTemplate() in the email body. When you create an email notification in Process Builder, specify evaluateTemplate( "templateFile" ) as the body script, where templateFile is the name of the template file relative to the application directory on the server. From Process Builder, you should include your template files in a folder called templates, a directory located in the application directory of Process Builder. When you deploy, the same directory structure is replicated on the server.
evaluateTemplate() also evaluates JavaScript segments contained in the template file. These segments are identified by <script language="Rhino"> tags.
In an HTML page containing client-side JavaScript, you can replace
<script language="JavaScript">
with
<script language="Rhino">
The PAE engine will evaluate the JavaScript in the same manner the browser does.
You can access the entire engine API (e.g., getProcessInstance(), getWorkITem(), etc.) from within these segments. To send output to an HTML file, use document.write() with the output you want to send provided as an argument.
evaluateTemplate() returns a string. The string is made up of the contents of the template file with the Rhino segments evaluated. If there are no Rhino segments in the file, the string simply contains the file contents. If there are Rhino segments, the string contains the evaluated JavaScript rather than the Rhino segments.
Example: .
var fileContents = evaluateTemplate( "templateFile" );
var cs = getContentStore():
cs.upload( fileContents, url ):
expireIn(val, unit)
Returns a JavaScript Date object set to the absolute datetime when the current work item will expire.
This function is normally used to specify the expiration time for a particular activity, and is usually set by the designer through Process Builder. In the event that you choose to specify the arguments for this function manually, the parameter unit can contain the following values:
Example:.
expireIn( 6, "minutes" ); // expire in 6 minutes
expireIn( 30, "days" ); // expire in 30 days
expireIn( 1, "month" ); // expire in 30 days
getAction()
Returns the name of the action (the button name) used to complete the current activity. The action name corresponds to the name of the button clicked when the work item form is submitted. This function can be used in any script, but is best used from the completion script of a user activity.
Example:.
function completion( )
{
var pi = getProcessInstance();
pi.setData( "submittedAction", getAction() ):
return true;
}
getApplicationName()
Returns the name of the application (for example: "wfDataSheet") as a string.
Example:.
var appName = getApplicationName();
java.lang.System.out.println( "The application name is: " + appName );
getApplicationPath()
Returns the pathname of the directory containing the files for this application as a string.
Example:.
var appPath = getApplicationPath();
java.lang.System.out.println( "The application path is: " + appPath );
getApplicationPrettyName()
Returns the pretty name of the application (for example: "DataSheet Management") as a string.
Example:.
var appPN = getApplicationPrettyName();
java.lang.System.out.println( "The application pretty name is: " + appPN
);
getBaseForFileName (processId)
Given a unique process instance ID, this function returns a string of the base file name for the content store for that process instance.
The following code creates a path name for the file myFile.html in the content store. Note that this code does NOT create the file, it simply creates a string that can be used as the file name by methods on a contentStore object, such as move() and store().
Example:.
var pi = getProcessInstance();
var pid = pi.getInstanceId();
var contentStorePath = getBaseForFileName (pid);
var newFileName = contentStorePath + "myFile.html";
getConnector(connectorKey)
Given a connector key, returns a connector object from the list of connector objects available for use by scripts.
Example:.
function initialisationScript( )
{
var c = new Packages.com.acme.DBConnection();
setConnector( "dbConnector" );
return true;
}
var c = getConnector( "dbConnector" );
getContentStore ()
Returns a contentStore object connected to the content store. See the section ContentStore for details of the methods on this object.
Example:.
var cs = getContentStore();
getContentStore(httpURL,user,password)
General purpose content store method. This method enables you to authenticate to arbitrary HTTP servers for file manipulation. You must have a content store object to use any of the content store methods.
Example:.
var publishCS = getContentStore(
"http://publish.netscape.com/CS", "sijacic", "password");
getCreatorUserId ()
Returns the user ID for the creator user of the current process instance.
This function is intended to be used as the initiate-as script for sub-process nodes. When the child process instance is created, its creator must be determined. Normally, the creator of the child process instance is the same user that authenticated with the server at the time the sub-process node was executed. However, it may be desirable (or necessary) to set the child creator to the same user as the creator of the parent process instance.
If you choose to use this function to change the child creator user, the authenticating (or current) user must be a member of the trusted users group in the child application.
Example:.
var pi = getProcessInstance();
var creatorUser = pi.getCreatorUser();
var creatorUserId = creatorUser.getUserId();
getCorporateDirectory ()
Returns a corporateDirectory object connected to the corporate directory in the Directory Server. See the section CorporateDirectory for details of the methods on this object.
Example:.
var corpDir = getCorporateDirectory();
__getIncludePath ()
Returns the current inclusion path used by the server to search for JavaScript source files. This search path resembles in behavior the PATH mechanism used in Windows NT and UNIX to search for executables and libraries when a file name is not absolute.
The directory installDir/resources/server/js (where installDir is PAE installation directory on the server machine) is included in the search path by default.
Example:.
// Returns the current search path
var includePath = __getIncludePath();
// Add our own directory to the search path
includePath += ';' + "d:\\tmp";
// Set the search path
__setIncludePath( includePath );
getJndiNamingContext()
Returns the current NAS JNDI naming context used to look up the home interface of an EJB.
Use this function to access EJBs from within a Custom Activity. You can pass the instance of the naming context to the Custom Activity and use the lookup() method on this context to obtain home interfaces of the beans.
Example:.
var namingContext = getJndiNamingContext()
getProcessInstance ()
Returns a JavaScript ProcessInstance object associated with the current work item.
See the section ProcessInstance for details of the methods on this object.
Example:.
var wi = getWorkItem();
var pi = getProcessInstance();
java.lang.System.out.println( "The Process Instance ID: " +
pi.getInstanceId() );
getSubProcessInstance ()
Returns a ProcessInstance object corresponding to the completed child process instance. This function should only be used from the completion script of a sub-process node. The object returned by this function has all the same methods expected of a ProcessInstance object, except that the information contained within corresponds to the completed child process instance instead of the parent. If this function is called from any location other than the completion script of a sub-process node, null is returned.
Example:.
// Completion script of sub-process node
function parentCompletion( )
{
var pi = getProcessInstance(); // parent process instance
var spi = getSubProcessInstance(); // child process instance
// Map some of the data elements from the child back to the
// parent process instance
pi.setData( "childStatus", spi.getData( "status" ) );
pi.setData( "numApprovers", spi.getData( "numApprovers" ) );
return true;
}
getWorkItem ()
Returns a workItem object that represents the current work item. See the section WorkItem for details of the methods on this object.
Example:.
var wi = getWorkItem();
__includeFile (fileName)
Reads in the contents of a JavaScript source file and evaluates the contents. Any JavaScript functions and objects defined within the file are available to all user scripts.
__includeFile() and its "helper" functions, __getIncludePath() and __setIncludePath(), are used by the server to define the built-in JavaScript functions available to user scripts.
If you want to access JavaScript functions or objects from user scripts and do not want to include the script files with every application you develop, you can externalize the functions in a separate JavaScript file and include the functions in the server's global run-time scope using __includeFile().
Example 1:.
// Sample JavaScript file
function checkCreator( userId )
{
var pi = getProcessInstance();
var u = pi.getCreatorUser();
// If the process instance creator matches the
// userId, return true, else false.
if( userId == u.getUserId() )
return true;
else
return false;
}
Example 2.
// Sample includeList.js file
var myIncludePath = "d:\\tmp";
var includePath = __getIncludePath() + ';' + myIncludePath;
__setIncludePath( includePath );
__includeFile( "myFunctions.js" );
mapTo(fieldName)
Used only from a custom activity as a means of mapping values from the output hashtable back to the process instance. The fieldName parameter specifies the name of a data element in the process instance. This data element receives the value of the current output parameter. When the custom activity's perform() call is complete, the server iterates through the hashtable, one element at a time, and attempts to map the element's value to a field in the process instance. Returns true if data mapping succeeds. Returns false if a problem has occurred.
Example:.
mapTo( "customerName" );
mount(jndiName)
Looks up and creates an instance of a stateless session bean, or EJB, found under the given JNDI name. If no bean exists under this name, a javax.naming.NamingException is thrown. PAE handles this exception by moving the process instance into the designated Exception Manager node. If the EJB can be found under the given JNDI name, an instance of it is created by calling the create() method on the returned home interface of the bean. This function call is equivalent to the ejbLookup(jndiName).create() function call.
Example:.
var creditServer = mount("Netscape/CreditCardServer");
setConnector(connKey, connObject)
Adds a connector object (such as a database connection) indexed by key to the list of connector objects that can be used by scripts.
Example:.
var pi = getProcessInstance();
var obj = new Object();
obj.machinename = "lint";
obj.username = "admin";
obj.passwd = "netscape";
setConnector("myConnector", obj);
__setIncludePath (includePath)
Allows the user to specify the path the server uses to search for JavaScript source files. The path is a delimited list of absolute directory path names. The delimiter depends upon the system:
Searches start from the first directory and proceed to the last directory until the file is located. The directory installDir/resources/server/js (where installDir is where PAE is installed on the server machine) is included in the search path by default. However, once you set your own path using this function, the current search path is overwritten. Thus, calls to __setIncludePath should specify the entire search path by appending the new search directory to the current search path.
Example:.
var includePath = __getIncludePath();
includePath += ';' + "d:\\tmp";
// Set the search path. Note how the variable includePath also
// specifies the existing search path. Every call to __setIncludePath
// overwrites the previous search path.
__setIncludePath( includePath );
setRedirectionURL(stringURL)
Redirects the participant's browser to the specified location in stringURL.
Invoke this method from a completion script. setRedirectionURL() is typically used for multiple-screen data entry where the same person may enter data across several screens or user activities. The process subsequently becomes a wizard-like forms entry screen.
Example:.
function scriptComplete( )
{
// Redirect to the Netscape Home Page
setRedirectionURL( "http://home.netscape.com" );
// This will cause the same process instance to display after the
// user clicks an action button
setRedirectionURL( url_OnDisplayProcessInstance() );
// Don't forget to return true; this is still a completion script
return true;
}
url_OnDisplayHistory()
Returns a string containing the URL that points to the history list for the current process instance. This function is usually used in conjunction with setRedirectionURL() to redirect a user to the history page of the current process instance.
Example:.
function scriptComplete( )
{
// Redirect to the History Page of this process instance
setRedirectionURL( url_OnDisplayHistory() );
}
url_OnDisplayProcessInstance()
Returns a string containing the URL that points the current process instance. This function is usually used in conjuction with setRedirectionURL() to redirect a user to the current process instance.
Example:.
function scriptComplete( )
{
// Redirect to the current process instance
setRedirectionURL( url_OnDisplayProcessInstance() );
}
url_OnDisplayWorkItem()
Returns a string containing the URL that points to the current work item. This function is usually used in conjuction with setRedirectionURL() method to redirect a user to the current work item.
Example:.
function scriptComplete( )
{
// Redirect to the current work item
setRedirectionURL( url_OnDisplayWorkItem() );
}
url_OnDisplayWorklist()
Returns a string containing the URL that points to the user's work list. This function is usually used in conjuction with setRedirectionURL() to redirect a user to their work list.
Example:.
function scriptComplete( )
{
// Redirect to the user to their work list
setRedirectionURL( url_OnDisplayWorklist() );
}
url_OnListApplications()
Returns a string containing the URL listing applications installed on the PAE cluster. This function is usually used in conjunction with setRedirectionURL() to redirect a user to the list of applications installed on the cluster.
Example:.
function scriptComplete( )
{
// Redirect to the list of applications on this cluster
setRedirectionURL( url_OnListApplications() );
}
url_OnListEntryNodes()
Returns a string containing the URL that points to the list of entry points in the current application. This function is usually used in conjunction with setRedirectionURL() to redirect a user to the list of entry points in the current application.
Example:.
function scriptComplete( )
{
// Redirect to the list of entry points of the current application
setRedirectionURL( url_OnListEntryNodes() );
}