4.2.17 JavaScript plug-in
Function
This plug-in can execute JavaScript code that converts JSON-formatted text. In the specified JavaScript code, the values of service properties and plug-in properties can be referenced. In addition, the functions provided by underscore.js 1.8.3 can be used.
Note that if you use the print function in JavaScript code, you can output any character string in the JavaScript code to the task log. In this case, you can specify the log level by adding one of the prefixes shown below. For example, to specify [Debug] as the log level, specify the function in print("[Debug]xxxx") format. The prefix is case sensitive.
-
[Severe]
The character string specified in the print function is output if the log level is 0 or higher.
-
[Information]
The character string specified in the print function is output if the log level is 10 or higher.
-
[Fine]
The character string specified in the print function is output if the log level is 20 or higher.
-
[Finer]
The character string specified in the print function is output if the log level is 30 or higher.
-
[Debug]
The character string specified in the print function is output if the log level is 40.
-
None
The character string specified in the print function is output if the log level is 10 or higher.
Cautionary notes
-
Encode the script with UTF-8, and use anonymous functions.
-
If an exception is thrown or occurs in the script, the plug-in terminates abnormally. If an exception occurs when the log level is 30 or higher, a stack trace is output to the task log.
-
If null or undefined is included in either of the following values, or both, when the script terminates normally, null or undefined is stored in output properties as an ordinary character string:
-
Value returned from the script
-
Value set for an output property of the plug-in in the script
-
-
If execution of a task is stopped during plug-in execution, the status of the task becomes Failed or Completed when the processing of the JavaScript plug-in has finished. The status of steps and tasks after plug-in execution has finished depends on the return code of the step and the condition for executing subsequent steps. You can set Subsequent-step Execution Condition in the Create Step dialog box or the Edit Step dialog box.
-
When you forcibly terminate a task while the plug-in is running, the processing being executed is immediately forcibly terminated and the task enters Failed status. A return code of 80 appears for the step in the Flow area of the Tasks window. The return code output to the task log depends on the timing in which the task was forcibly terminated.
Version
01.00.02
Tag
Execute Script
Return codes
Return code |
Description |
---|---|
0 |
Ended normally. |
1 |
The JavaScript code terminated, specifying a non-null value for the notify output property. |
60 |
Failed to load the JavaScript library. |
61 |
Failed to compile the JavaScript code. |
62 |
The JavaScript code is not of the function type. |
63 |
An internal error occurred. |
80 |
Task execution has stopped. |
Property list
The following table describes the properties.
Property key |
Property name |
Description |
Default value |
I/O type |
Required |
---|---|---|---|---|---|
scriptBody |
JavaScript body |
Specify the desired JavaScript code. |
-- |
Input |
R |
importedScript |
Imported script |
Specify the methods and constants (strings of JavaScript code) that are shared with other JavaScript plug-ins used in the same service template. |
-- |
Input |
O |
arg0 |
Argument(0) |
Specify an argument to be passed to the JavaScript code. The string arg0 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg1 |
Argument(1) |
Specify an argument to be passed to the JavaScript code. The string arg1 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg2 |
Argument(2) |
Specify an argument to be passed to the JavaScript code. The string arg2 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg3 |
Argument(3) |
Specify an argument to be passed to the JavaScript code. The string arg3 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg4 |
Argument(4) |
Specify an argument to be passed to the JavaScript code. The string arg4 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg5 |
Argument(5) |
Specify an argument to be passed to the JavaScript code. The string arg5 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg6 |
Argument(6) |
Specify an argument to be passed to the JavaScript code. The string arg6 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg7 |
Argument(7) |
Specify an argument to be passed to the JavaScript code. The string arg7 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg8 |
Argument(8) |
Specify an argument to be passed to the JavaScript code. The string arg8 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
arg9 |
Argument(9) |
Specify an argument to be passed to the JavaScript code. The string arg9 specified in the JavaScript code will be replaced with the value specified for this property. |
-- |
Input |
O |
notify |
Notification flag |
If you want the plug-in to terminate abnormally in the event of an abnormality in the specified JavaScript code, set the script to output a non-null value to this property. If the value of this property is not null after executing the script, 1 is returned as the return code of the plug-in. |
-- |
Output |
O |
returnValue |
Return value |
The contents of the object returned within the function in the specified script are output to this property. |
-- |
Output |
O |
out0 |
Output(0) |
The value set as out0 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out1 |
Output(1) |
The value set as out1 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out2 |
Output(2) |
The value set as out2 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out3 |
Output(3) |
The value set as out3 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out4 |
Output(4) |
The value set as out4 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out5 |
Output(5) |
The value set as out5 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out6 |
Output(6) |
The value set as out6 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out7 |
Output(7) |
The value set as out7 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out8 |
Output(8) |
The value set as out8 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
out9 |
Output(9) |
The value set as out9 for the Map second argument in the specified script is output to this property. |
-- |
Output |
O |
JavaScript code arguments that can be specified in the JavaScript body
The following arguments can be specified as JavaScript code:
- serviceProperties (object type)
-
This argument can be used to map the values of input properties for the service. Note that even if the script changes the value of this argument, the change is not applied to the service properties.
- pluginProperties (object type)
-
This argument can be used to map the values of properties for the JavaScript plug-in.
-
arg0 to arg9
The values specified for plug-in properties are mapped. In this case, the values are obtained as character strings rather than as objects.
-
notify
If a non-null value is set for this member in the script, the plug-in returns 1.
-
out0 to out9
If a value is set for these members in the script, the values are applied to plug-in properties out0 to out9.
-
- arg0 to arg9
-
The values specified for plug-in properties arg0 to arg9 are mapped. Note that JSON-formatted character strings specified for these properties are obtained as objects.
Specify the above arguments in the following order: 1) serviceProperties (object type), 2) pluginProperties (object type), and 3) arg0 to arg9
Sample JavaScript code
(function(serviceProperties, pluginProperties, arg0, arg1, arg2) { var obj = new Object(); print("[Debug] Function begin."); obj.mem1 = arg0; obj.mem2 = arg1; if (arg2 == "") { pluginProperties["notify"] = 999; pluginProperties["out1"] = "NOTE!: The arg2 is EMPTY."; } else { obj.mem3 = arg2; obj.status = "success"; pluginProperties["out1"] = "Finished successfully."; } print("[Debug] Function end."); return obj; })
About imported scripts
If you want to share methods and constants with other JavaScript plug-ins used in the same service template, define the methods and constants in the importedScript property.
By mapping the importedScript property to the service input property, and then mapping the importedScript properties of other JavaScript plug-ins to the same service input property, you can share the methods and constants defined in the imported script, with the JavaScript body of each JavaScript plug-in.
-
Referencing methods and constants from the JavaScript body
The methods and constants defined in the imported script can be used by directly calling them from the JavaScript body.
-
Functions that can be used in the imported script
The functions that can be used in the JavaScript body can also be used in the imported script.
Sample imported script
- JavaScript body
function fn(serviceProperties, pluginProperties, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) { hoge(CNST); }
- Imported script
var CNST = "hoge"; function hoge(a){ print(a + " from common js!"); }