Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

This component is used for executing JavaScript. The JavaScript to be executed is specified using the Custom Property Sheet (CPS). This component executes the script on documents it receives as input and returns the result.

  • The component uses the document object to get the content and properties of the message. The result after executing of the script should be set back onto the document object.
  • The component uses "bsf" API to evaluate the script.

Points to Note

  • Input message content and properties can be accessed using document object. For example, 'document.getText()' returns input message content. To access a message property named 'TestProperty, 'document.getRecord().getProperty('TestProperty')' returns the value of the property. All the Properties can be accessed using document.getRecord().getProperty('PropertyName').
  • Message properties can be set using 'document.getRecord().setProperty(String name, Object value)' method.
  • Message properties which are set on input message also appear on output message unless they are changed in the script. For example, if a property named 'TestProperty' is present on input message then output message also contains the property unless it is changedinscriptprovided.
  • Output message content can be set either by using 'document.setText(String value)' of document object.
  • In message properties, property with name 'ESBX__SYSTEM__CARRY_FORWARD_CONTEXT' contains applicationcontextobject.
    Application context schema can be accessed using document.getRecord().getProperty("ESBX__SYSTEM__CARRY_FORWARD_CONTEXT").getAppContext() method.
    Similarly setAppContext(String appContext) can be used to modify application context.
  • JMS Correlation ID can be accessed/set using document.getRecord().getJMSCorrelationID() and document.getRecord().setJMSCorrelationID(String correlationID) methods.
  • document.getRecord() return an instance of ESB Record which can be referred to by users for performing any other advanced operations.

Accessing Source Contexts

Carry forward context contains a vector of source context objects in the service execution order. This vector is updated after every service instance execution.

Following code returns an Enumeration of Source context objects.

Code Block
contexts = document.getRecord().getProperty("ESBX__SYSTEM__CARRY_FORWARD_CONTEXT").getContexts();
  • contexts.hasMoreElements() can be used to iterate overtheenumeration
  • contexts.nextElement() can be used to get the context object.

Context object contains Service Instance Name, Application Name, Application Version, Node Name. Following codes can be used to access the respective fields.

getSrvInstName()Returns Service Insatnce Name for this context object.
getAppInstName()Returns Application Insatnce Name to which service instance belongs.
getNodeName()Returns Node Name on which service instance is running.
getAppInstVersion()Returns Version of the application to which service instance belongs.


Following script can be used to get the list of service instances that a message has passed through

Code Block
contexts = document.getRecord().getProperty("ESBX__SYSTEM__CARRY_FORWARD_CONTEXT").getContexts();
instanceList = "";
instanceList = instanceList + contexts.nextElement().getSrvInstName() + ",";


Configuration and Testing

Interaction Configuration

Figure 1: Interaction Configurations panel in JavaScript CPS


Pre Processing XSL Configuration

Pre Processing XSL configuration can be used to transform request message before processing it. Click the ellipses button against the property to configure the properties.

Refer to the Pre/Post Processing XSL Configuration section under the Common Configurations page for details regarding Pre Processing XSL configuration and Post Processing XSL configuration (below).

Post Processing XSL Configuration 

Post Processing XSL configuration can be used to transform the response message before sending it to the output port.

Process Message Based on Property

The property helps components to skip certain messages from processing.

Refer to the Process Message Based On a Property section under the Common Configurations page.

Read Script from file?

If enabled, Script file path property appears where you can provide the location where the script file is saved.

Script File Path

Provide the complete path of the Java Scriptfile(file should have .js extension) which you want to execute.

Figure 2: Script file path property to provide the location where the script file is saved


If Read Script from file ?property is disabled, populate the JavaScript property with theJava Script.

Replace Control Characters 

 If this property is enabled, Control Characters present in the input will be replaced by a string representation of the same value during script evaluation. This is an expert property.


Cleanup resources (excluding connection) after each document


This closes all the resources except for the connection after every request. If the less processing time is more important the less memory usage, then it is recommended to disable this property and vice versa.


For more details, refer to the respective section under in the Common Configurations page.


Target Namespace


Refer to the Target Namespace section under the Common Configurations page. 


Monitoring Configuration


Please refer to the Monitoring Configuration section in Common Configurations page.

Scheduler Configuration

Please refer the respective section in Common Configurations page.

Transport Configurations

Please refer the respective section in Common Configurations page.


Transport Configurations panel will be available only if scheduling is enabled in Scheduler Configurations panel.

Error Handling

Please refer the sections Request Processing Error and Invalid Request Error in the Error Handling section of Common Configurations page for details.

Sample Input and Output

The configuration can be tested by clicking the Test button in the interaction Configuration panel.

Below is asampleJavascript.

Code Block
var time = 15;
if (time < 10) {
    document.setText("Good morning")
} else {
    document.setText("Good Day")

Below are the sample input and the output respectively for the above script.

Figure 3: Sample Input Message

Figure 4: Response Generated

Functional Demonstration


Execution of Java Script provided.

Configure theJavaScriptasdescribed in Configuration and Testing section and use feeder and display component to send sample input and to check the response respectively. In the example given below, the script provided is:

Code Block
var r = Math.random()
if (r > 0.5) {
    document.setText("<a href=''>Learn Web Development!</a>")
} else {
    document.setText("<a href=''>Visit Refsnes Data!</a>")

Figure 5: Scenario demonstration with sample input and output

Useful Tips

The component uses the document object to get the content and properties of the message. The Script  Execution result should be set back onto the document object.

In message properties, property with name "ESBX__SYSTEM__CARRY_FORWARD_CONTEXT" contains applicationcontext object.
Application context schema can be accessed using document.getRecord().getProperty("ESBX__SYSTEM__CARRY_FORWARD_CONTEXT").getAppContext().
Similarly setAppContext(String appContext) can be used to modify application context.


Adaptavist ThemeBuilder EngineAtlassian Confluence