Run Script / Execute Script

Description

Run a JavaScript script.

Typically available as two services: RunScript (with runType of include) and ExecuteScript (with runType of execute).

Input

<RunScript>
<userLogonReference>userid</userLogonReference>
<password>password</password> <runType>include|execute</runType> <nodeVersionIdentifier/> <nodeVersionReference/> <nodeVersionIdentifierMethod/> <nodeVersionReferenceMethod/> <script/> <wait>true|false</wait>
</RunScript>

User logon reference and password are optional. If they are given, they must be correct.

The script can be specified either by passing a script in using the <script> element, or by identifying the node and method (member) containing the script.

In all cases, the script is read from the member identified bu nodeVersionIdentifierMethod or nodeVersionReferenceMethod.

The runType identifies how the script should be run:

include The script is read from the specified node.

The user only needs read authority on the data.

execute The script is read from the type of the specified node.

The user must have execute authority on the specified node.

The specified node will be set as the context of the script.

The method (member type) defaults to system.NODE_SCRIPT.

Nodes can be specified by id or reference, id takes precedence.

The <script> element will only be used if no node is specificed.

Inside the script, the original request, without credentials, is available as an XPathEvaluator object in attribute "request".

The credentials from the request are saved within the script's credentials object.

For a runType of include, the user must have read authority over the specified node/method member type.

For a runType of execute, the user must have execute authority over the specified node.

runType, nodeVersionReference, nodeVersionReferenceMethod, script and wait all default to the like-named configuration parameter. Together with runType, this allows new script-based services to be defined. nodeVersionReferenceMethod will be picked up from the same place as nodeVersionReference, i.e. you can not pick up one from config and one from the parameters.

wait indicates whether the service should wait for the script to run. The default is true. If wait is false, then the script will be submitted in the background. If there are errors in the running script then if the a node is specified and one of the execute run types is used, then the error will be written to the system.NODE_ERROR member of the node. In other cases, when wait is false and there is an error, the script will fail silently (though the error will be logged).

Output

The script can return any output. The default is:

<RunScript>
<errorNumber>0</errorNumber>
</RunScript>

Errors

Any

Class

com.metrici.xerula.RunScriptService