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.
Note |
---|
- 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.
- Message properties can be set using 'setProperty' 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 changed in script provided.
- Output message content can be set either by using 'setText(String value)' of document object.
Anchor |
---|
| _Toc372741081 |
---|
| _Toc372741081 |
---|
|
Configuration and Testing
Anchor |
---|
| _Toc372741082 |
---|
| _Toc372741082 |
---|
|
Interaction Configuration
![](/documentation/download/attachments/6233644/image2014-7-28%2018%3A46%3A12.png?version=2&modificationDate=1406553371000&api=v2)
Figure 1: Interaction Configurations panel in JavaScript CPS
Attributes
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 Script file (file should have .js extension) which you want to execute.
![](/documentation/download/attachments/6233644/image2015-4-8%2013%3A51%3A25.png?version=2&modificationDate=1428481287000&api=v2)
Figure 2: Script file path property to provide the location where the script file is saved
JavaScript
If Read Script from file ? property is disabled, populate the JavaScript property with the Java Script.
Note |
---|
- For the Expert Properties such as Cleanup resources (excluding connection) after each document and Target Namespace, Elements to Decrypt and Elements to encrypt, refer respective sections in Common Configurations page.
- For Monitoring configuration property too, refer the respective section in the above-mentioned page.
|
Scheduler Configuration
Please refer the respective section in Common Configurations page.
Transport Configurations
Please refer the respective section in Common Configurations page.
Note |
---|
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.
Anchor |
---|
| _Toc372741083 |
---|
| _Toc372741083 |
---|
|
Sample Input and Output
The configuration can be tested by clicking the Test button in the interaction Configuration panel.
Below is a sample Java script.
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.
![](/documentation/download/attachments/6233644/worddav8b000b124b6cb349231f4f321671259e.png?version=2&modificationDate=1399898274000&api=v2)
Figure 3: Sample Input Message
![](/documentation/download/attachments/6233644/worddav043cf2558b2b604b6da854bca3fecd34.png?version=2&modificationDate=1399898274000&api=v2)
Figure 4: Response Generated
Anchor |
---|
| _Toc372741084 |
---|
| _Toc372741084 |
---|
|
Functional Demonstration
Anchor |
---|
| _Toc372741085 |
---|
| _Toc372741085 |
---|
|
Scenario
Execution of Java Script provided.
Configure the Java Script as described 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='http://www.w3schools.com'>Learn Web Development!</a>")
} else {
document.setText("<a href='http://www.refsnesdata.no'>Visit Refsnes Data!</a>")
} |
![](/documentation/download/attachments/6233644/worddav930f4fe100e9b6a46ff8eecdaf8b35b0.png?version=2&modificationDate=1399898274000&api=v2)
Figure 5: Scenario demonstration with sample input and output
Anchor |
---|
| _Toc372741086 |
---|
| _Toc372741086 |
---|
|
Useful Tips
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.