jcu-eresearch / matrix-helpers

100% Unguessable™. Public bug tracker, pages, designs and helpers that make life in Squiz Matrix easier. The metaphorical red pill.
https://jcu-eresearch.github.io/matrix-helpers/
GNU Affero General Public License v3.0
3 stars 0 forks source link

Matrix API for Server-Side JavaScript #55

Open davidjb opened 7 years ago

davidjb commented 7 years ago

At the moment, the only way to get data in or out of SSJS is via keywords. These only get processed before an SSJS block is executed for data going in -- or after for controlling behaviour afterwards. Whilst fairly straightforward for simple situations (eg passing IDs in as strings), trying to pass a multi-line string (eg asset contents) or datatype is hard, potentially requiring detailed workarounds. Moreover, what isn't possible at present is resolving keywords or querying an API for metadata, page contents, link types, status etc (really any type of data) from within the SSJS so you can use the data to make decisions, perform processing and generate output. Here's a basic contrived example:

var prefix = global ? "gloabls_asset" : "asset"
var assetID = '%' + prefix + '_metadata_setting%' // Won't evaluate unless printed out of SSJS
if (value.match(/Site/) || value === 'other') {
  // Do something, like printing children  for (child in js_api.getChildren(assetID) { // Doesn't exist    print(...)
  }
}

The second line will only resolve the keyword after being print()'d, meaning its value can't be used for in further SSJS processing or decision making.

Reported at https://squizmap.squiz.net/matrix/10541

davidjb commented 7 years ago

Accepted for implementation by vendor. Updates to follow.