Straatos Script Service API

This articles describes Straatos Scrip Service API

Straatos engine provides JavaScript activity. This document describes available calls for developers writing JavaScript activities.

Available Variables

Constants are declared and initialised by Straatos. They cannot be changed, just queried.

circle-info

Constants are case sensitive.

Name
Description

workflowId

ID of workflow this workflowInstance is in. WorkflowId changes every time workflow is (re-)published.

workflowName

Name of workflow

workflowInstanceId

Unique ID of every workflowInstance. This will not change as long as the instance is in the workflow.

activityId

Uniquely identifies activity within current workflow.

activityName

Name of Script activity

activityInstanceId

Increasing sequence number representing logId of activity

activityInstanceDate

Date that activity execution started

workflowInstanceDate

Date the workflowInstance arrived in the workflow

console

Object with method log(String). Output will appear in efektif log.


Utility Methods

JavaScript activity provides “Straatos”-object containing several methods providing functionality. The following are description of these methods:

Generate a UUID

Generate a UUID (or GUID), please use:


Sequence Number

The method nextSequenceNumber() generates sequence number that is unique for the workflow.

Identifier makes it possible to have several sequences in one process:

Name
Description

nextSequenceNumber()

Retrieves the next sequence number for the specified identifier

clearSequenceNumber()

Clears the sequence (ie it will start at 1 again)

Sample Code


Getting Variables from Other WorkflowInstances in the Same Flow

Straatos provides two ways to get variables from other workflowInstances in the same workflow.

Name
Description

variablesByWorkflowInstanceId('')

Gets variables of workflowInstance defined by

variablesByDocumentId()

Gets variables of workflowInstance defined by (every workflowInstance also has unique documentId attached)

Sample Code


Getting activityIds, documentId and workflowInstanceId

The ActivityId is used in multiple API methods, such as the message() method, to identify a specific activity within a workflow.

Getting ActivityId by Name

The method activityIdForName(activityName) allows you to retrieve the ActivityId when you provide an ActivityName.

Key Points:

  • ActivityId is a unique identifier for an activity in a workflow.

  • ActivityName is the user-defined name/description of an activity.

  • The activityIdForName(activityName) method helps map the activity name to its corresponding ID.

Name
Description

activityIdForName()

Returns activityId for the given activityName (only works for the current workflow, ie workflow the workflowInstance is in)

getActivityIdsByDocumentId()

Returns list of activityIds where workflowInstance defined by DocumentId is in (there is a 1:1 relation between documentId and workflowInstanceId).

getWorkflowInstanceIdByDocumentId()

Get workflowInstanceId (a string) for specified documentId

documentIdsForFilter()

Perform search on all documents on given variables

Sample Code


Getting Variable Values

It is possible to get variables from other workflowInstances in the same workflow using these methods:

Name
Description

variablesByDocumentId()

Gets JSON string containing all variables by documentId

variablesByWorkflowInstanceId()

Gets JSON string containing all variables by workflowInstanceId


Converting to-and-from Byte Arrays

Several convenience methods are provided to convert to and from byte arrays.

Name
Description

getBytes(inputString)

Converts inputString to byte array, using UTF-8 encoding.

getString(byte[])

Converts byte array to a string, using utf-8 character set.

getString(<byte[]>, )

Convert byte array to a string, using specified character set.


Base64 Encoding and Decoding

Name
Description

decodeBase64()

Returns (possibly binary) byteArray of base64 encoded string.

encodeBase64()

Returns base64 encoded string representation of (binary-) byteArray.

Sample Code


Workflow Data

Functionality is provided to store and retrieve data on workflow level. This data remains available when the workflow is re-published.

Name
Description

setWorkflowData(, )

Sets workflow data.

getWorkflowData()

Gets workflow data for specified key

removeWorkflowData()

Removes workflow data for specified key

clearAllWorkflowData()

Removes all workflow data for current workflow

Example:


Messaging Other WorkflowInstances

Send other (waiting) workflowInstances a message that they can continue the workflow.

Name
Description

sendWorkflowMessage({})

Sends a message to workflowInstance. Message should contain workflowId, activityId and an array of workflowInstances to message. Optionally variables per workflowInstance. See example below.

Parameters:

  • workflowId:

    • ID (a guid) of current workflow.

  • activityId:

    • ID (a string) of activity. See activityForName() method to get activityId via activityName.

  • workflowInstances:

    • List of one or more workflowInstances that should receive the message.

Each workflowInstance should contain workflowInstanceId and optionally list named variables of id-value pairs.

Sample Code


Calling Web Services (Ajax Support)

Straatos provides an api to call web services. The way it can be used is similar to a jQuery Ajax call, however, it supports a subset of the functionality.

This Ajax call can also be used to call additional functionality the Straatos REST API provides. For more information, please open the link below.

https://docs.google.com/document/d/1ui5UhztqodEmLn6rY36AQ00rUsiLKfwNNvXdzLw6CJ0/edit?ts=5829c792#bookmark=id.fccwvtqnhhu3arrow-up-right

Name
Description

ajax()

Performs the call. See table below for the request options

Request specification:

Name
Description

url

Required: Complete url to call. Calls to urls containing localhost are not allowed.

data

Data you want to pass, or the multipart object from straatos.newFormData call

method

Possible values are GET, POST, PUT, DELETE and OPTIONS. When not specified, it defaults to GET

contentType

Optional contentType of data to be sent, default is 'application/json'

dataType

Optional contentType of expected data for example: 'binary' or 'text/html'

headers

Optional array with headers that will be passed to the call

timeout

Optional timeout in milliseconds. The default is 60 seconds. This one parameter specifies connectTimout, requestTimeout and socketTimeout.

Sample Code


Multipart Support

Multipart support is available to create multipart messages. If boundaries are needed between parts, they should be added manually by the developer.

To get a new Multipart object, call straatos.newFormData().

Adding Data

To add data to multipart objects, call one of these methods:

Name
Description

append()

Adds a string, this string will be utf-8 encoded

append(, )

Adds a string with a custom character set. Values used can be ‘utf-8’, or any of the character sets from the table below.

append(<byte []>)

Appends a byte array to multipart object

Getting Data

To get the data from the multipart object, call one of these methods:

Name
Description

getByteArray()

Returns byte array (byte[]) representing multipart data

toString()

Returns utf-8 decoded string of multipart data

Sample Code


Getting History or Audit Trail Info

This API call returns JSON string containing history of the document. This will not include the currently executed step.

  • straatos.history() returns json string containing history of the current workflowInstance (not including current running activity).

  • straatos.history(number documentId) returns json string containing history of workflowInstance identified by documentId provided. This document must be part of the same workflow as the calling document.

Since a string is returned, JSON.parse() should be called on the string before accessing json objects within the returned data.

Sample Code


setSecret and getSecret

The Set Secret and Get Secret functions provided by the Script task or Interact API enable the secure storage of sensitive data such as passwords, tokens, API keys, and connection strings.

How It Works:

  • setSecret:

    • This function securely stores the data in Straatos's vault.

  • getSecret:

    • This function retrieves the stored data from the vault for use within the workflow.

Best Practices:

  • It is crucial not to store secrets directly in script code. Instead, utilize the setSecret and getSecret functions to manage sensitive data securely.

Storing a Secret

The above code stores the return value in a variable. That variable will either contain a 'true' or 'false' value, depending on if the storing of the secret was successful. This result should be checked by the code.

Retrieving a Secret


Database (SQL) Queries

The straatos.data.query lets user connect to a database and execute SQL queries. This function can be used to read data from Database (Select), but also to update, truncate, drop databases (tables).

The sample code below shows how a database is updated.


Supported Character Sets

Supported charsets (java might support more, but this is the minimum).

  • US-ASCII Seven-bit ASCII, a.k.a. ISO646-US.

  • ISO-8859-1 ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.

  • UTF-8 Eight-bit UCS Transformation Format.

  • UTF-16BE Sixteen-bit UCS Transformation Format, big-endian byte order.

  • UTF-16LE Sixteen-bit UCS Transformation Format, little-endian byte order.

  • UTF-16 Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark.

Last updated