Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page documents following objects provided by Canvas and which can be used in block JS-code:Canvas has several useful helper functions built in which will help you speed up integration development.

There are functions for storing values between runs (myVault), checking when the workflow last ran (dateLastRun), logging data (logger), storing session variables (session), in addition to a large library of application specific functions (see the fx docs in Canvas).

This page provides an overview of these helper functions, which can all be used inside block code.

Table of Contents
minLevel1
maxLevel12

Packages

All The following packages are provided by Canvas, and which can be used in block JS-Javascript code:

Table of Contents
minLevel2
maxLevel2
includeapi|fx|logger|myVault

api

api package contains methods for working with CMA API.

...

Table of Contents
minLevel3
maxLevel3
includeapi.get|api.getDirect|api.post|api.postDirect*

api.get

Sends get request to endpoint by specified url. Is asynchron method.

...

Expand
titleExample
Code Block
//get list of all endpoints provided for MyStore application
var response = await api.get('myst2/meta');

api.getDirect

Sends get request to endpoint on specified CMA API server by specified url. Is asynchron method.

...

Expand
titleExample
Code Block
//get list of all endpoints provided for MyStore application
var response = await api.getDirect('myst2/meta', 'cmaeu3');

api.post

Sends post request to endpoint by specified url. Is asynchron method.

...

Expand
titleExample
Code Block
let newProduct = { 
    "number": "000TS-01",
    "name": "T-short Adidas White XS",
    "vatType": 31
};
var response = await api.post('trip2/product', newProduct);

api.postDirect

Sends post request to endpoint on specified CMA API server by specified url. Is asynchron method.

...

Expand
titleExample
Code Block
let newProduct = { 
    "number": "000TS-01",
    "name": "T-short Adidas White XS",
    "vatType": 31
};
var response = await api.post('trip2/product', newProduct, 'cmaeu3');

fx

fx is a package, which contains functions provided by CMA, but also can be increased by organizations specific functions. Some functions are grouped by packages including applications specific functions.

Full documentation of all functions you can get by this link.

logger

logger is a package which helps to work with User Logs in block JS-code.

...

Expand
titleExample
Code Block
logger.log('Hello world!');'Hello world!');
Code Block
return arr;
Note

Please note that following values will be converted to null and logged as null then:

  • undefined

  • NaN

  • Infinity

  • '' - empty string

myVault

myVault is a package which contains methods for working with collections of keys-value pairs. All methods are grouped by access level type:

...

There are myVault methods which you can call in js-code:

Description

Workflow level

Account level

Writes key and value into myVault dictionary

set

setGlobal

Writes key and value into myVault dictionary on the workflow complete event

setOnComplete

setGlobalOnComplete

Reads value from myVault dictionary by specified key

get

getGlobal

Removes key-value pair from myVault dictionary by specified key

remove

removeGlobal

Determines whether the myVault dictionary contains the specified key

contains

containsGlobal

myVault.set

Writes key and value into myVault dictionary belonged to the workflow.

...

Expand
titleexample #3
Code Block
let keys =  [1, 2, 3, 4, 5];
let value = fx.utcNow();
await fx.forEach(keys, async(key)=> { 
    await myVault.set(key, value); 
});

myVault.setGlobal

Writes key and value into Global myVault dictionary belonged to the account.

...

Expand
titleexample #3
Code Block
let keys =  [1, 2, 3, 4, 5];
let value = fx.utcNow();
await fx.forEach(keys, async(key) => { 
    await myVault.setGlobal(key, value); 
});

myVault.setOnComplete

Writes key and value into myVault dictionary belonged to the workflow.

This method differs from myVault.set method in “saving into myVault is deferred” condition and will be executed on workflow complete event.

...

Please also see session.vault by this link

Please see conditionas for “Workflow complete“ by this link

myVault.setGlobalOnComplete

Writes key and value into Global myVault dictionary belonged to the account.

This method differs from myVault.setGlobal method in “saving into Global myVault is deferred” condition and will be executed on workflow complete event.

...

Please also see session.vaultGlobal by this link

Please see conditionas for “Workflow complete“ by this link

myVault.get

Reads value from myVault dictionary by specified key.

...

Expand
titleexample #3
Code Block
let keys =  [1, 2, 3, 4, 5];
let values = [];
await fx.forEach(keys, async(key) => { 
    values.push(await myVault.get(key)); 
});

myVault.getGlobal

Reads value from Global myVault dictionary by specified key.

...

Expand
titleexample #3
Code Block
let keys =  [1, 2, 3, 4, 5];
let values = [];
await fx.forEach(keys, async(key) => { 
    values.push(await myVault.getGlobal(key)); 
});

myVault.remove

Removes key-value pair from myVault dictionary by specified key.

...

Expand
titleexample #3
Code Block
let keys =  [1, 2, 3, 4, 5];
await fx.forEach(keys, async(key) => {
    await myVault.remove(key); 
});

myVault.removeGlobal

Removes key-value pair from Global myVault dictionary by specified key.

...

Expand
titleexample #3
Code Block
let keys =  [1, 2, 3, 4, 5];
await fx.forEach(keys, async(key) => {
    await myVault.removeGlobal(key); 
});

myVault.contains

Determines whether the myVault dictionary contains the specified key

...

Expand
titleexample #3
Code Block
let keys =  [1, 2, 3, 4, 5, 6, 7, 8, 9];
keys = await fx.filter(keys, async(key) => { 
    return await myVault.contains(key); 
});

myVault.containsGlobal

Determines whether Global myVault dictionary contains the specified key

...

Expand
titleexample #3
Code Block
let keys =  [1, 2, 3, 4, 5, 6, 7, 8, 9];
keys = await fx.filter(keys, async(key) => { 
    return await myVault.containsGlobal(key); 
});

Properties

All properties provided by Canvas and which can be used in block JS-code:

Table of Contents
minLevel2
maxLevel2
includeDatasource|dateLastRun|session

Datasource

Datasource is an array of block responses, which dependency is set for the block

...

Please see also Response by this link

dateLastRun

dateLastRun is a global workflow property which can be used in js-code. The property value is a date and time when a workflow was processed successfully last time. If workflow is a new and has not been run before, then property value is NULL.

You can see the value of workflow dateLastRun on the Workflow list page or read this value in js-code.

Rules when dateLastRun is updated

There is a list of cases when dataLastRun is updated:

...

You can know how to stop workflow running by this link

session

session is an object which is shared between all blocks in the workflow and contains following properties:

Table of Contents
minLevel3
maxLevel3
includesession.*

session

...

is stored for each workflow running. session is empty when new run is started (from first block) and is passed to next blocks till last. If you start running not from 1st block, for example from 3nd block, then session will be copied from 2nd block of previous running.

session.vault

session.vault is an object of keys-value pairs which was set by myVault.setOnComplete() method and which will be moved into myVault on workflow complete event.

...

Note

Please note that overriding of session.vault is forbidden.

For example, you will not be able to set following:

session.vault = [];

session.vault = null;

session.vault = 5;

session.vaultGlobal

session.vaultGlobal is an object of keys-value pairs which was set by myVault.setGlobalOnComplete() method and which will be moved into Global myVault on workflow complete event.

...

Note

Please note that overriding of session.vaultGlobal is forbidden.

For example, you will not be able to set following:

session.vaultGlobal = [];

session.vaultGlobal = null;

session.vaultGlobal = 5;

session.vars

session.vars is an object which Canvas provides for keeping of global variables in workflow context, which are not included into block responses.

...

Note

Please note that overriding of session.vars is forbidden.

For example, you will not be able to set following:

session.vars = [];

session.vars = null;

session.vars = 5;

Methods

Canvas provides just 1 method which can be used in block JS-code, it is getVariables().

getVariables()

Returns array of block variables. No parameters.

Expand
titleExample

let v = getVariables();

let url = `quin/Sections?apikey=${v.apiKey}`;

let sections = await api.get(url);

getWorkflowVariables()

Returns array of workflow variables. No parameters.

Expand
titleExample

let v = getWorkflowVariables();

let url = `quin/Sections?apikey=${v.apiKey}`;

let sections = await api.get(url);

...