Hitachi

JP1 Version 12 JP1/Automatic Operation Service Template Reference


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.

Cautionary notes

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.

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!");

}