'svcscript' capability for WebSocket Token API

Contents

Overview

Starts a service script passing start parameters and specifying an execution timeout. The response arrives after the script finishes. On successful completion the response contains an object with the values of all local variables.

Script execution and waiting for the response can be interrupted by sending an abort_svcscript request with the same qid value as the original start_svcscript request. In this case a response to the request named abort_svcscript_result arrives immediately.

If there is a parameter or startup error, the response message is returned immediately. If the responsible microservices are unavailable, the timeout before sending a failed response can reach 5 seconds.

Parameters startparam1, startparam2, …​, startparam20 can be set. Start parameters are passed to the script and are available in expressions via the startparam(N) function. The first start parameter is available in the Start component for saving into a variable.

The timeout parameter can be set in milliseconds (default 10000). After the timeout expires, waiting for the response is interrupted, and the script is also interrupted after the next component.

If scripts need to be executed asynchronously, it is enough to send requests with unique qid values and not wait for responses.

Example request
[
  "start_svcscript",
  {
    "qid": 123,
    "code": "test_script",
    "startparam1": "abc",
    "startparam2": "def",
    "startparam5": "{\":a\":1}",
    "startparam12": "[{\"a\":\"123\"}\r\n,{\"a\":\"456\"}]",
    "timeout": 5000
  }
]
Example response after script completion
[
  "start_svcscript_result",
  {
    "qid": 123,
    "result": "ok",
    "data": {
      "variables": {
        "body": "[{\"a\":1,\"b\":\"111\"},\n{\"a\":2,\"b\":\"222\"},\n{\"a\":1,\"b\":\"333\"},\n{\"b\":\"444\"},\n{}]",
        "code": 36,
        "err": "",
        "path": ":SYNC/common/1.txt",
        "text": "hello"
      }
    }
  }
]
Example response after abort.
[
  "abort_svcscript",
  {
    "qid": 123,
    "result": "ok"
  }
]

Parameters:

  • code - service script code in the domain.

  • startparamN - parameter passed to the script.

  • timeout - script execution timeout in milliseconds.

  • result - result code.

  • data - object with result details.

  • variables - object with the values of all local script variables.