SMARTBLOCKS:_DEVELOPER_DOCS

{{[[embed]]: ((3VJxxNhEu))}}

Technical notes for JavaScript developers working with SmartBlocks

Overview

Roam42 maintains a set of global objects that are updated when a workflow is in process. A JavaScript developer can read these values and in some cases change them to affect the flow of a workflow.

roam42.smartBlocks.activeWorkflow

activeWorkflow contains information about the current workflow being run. When the next workflow begins, all values in this object are reset to null except for roam42.smartBlocks.activeWorkflow.vars.

As a convenience, there is a short version of this object called roam42.sb which can make code less verbose.

roam42.smartBlocks.activeWorkflow.vars

This is a shared variable storage for workflows. GET and SET read variables from this object, which is an associative array. Example:

<%SET:MyVar,MyValue%> can be retrieved with:

roam42.smartBlocks.activeWorkflow.vars["MyVar"];

Or set in JavaScript with:

roam42.smartBlocks.activeWorkflow.vars["MyVar"] = "NewValue";

Note: the vars object does not persist, use localStorage from the browser if you need persistence

roam42.smartBlocks.activeWorkflow.blockContents

When the JAVASCRIPT and JAVASCRIPTASYNC commands are processed, this variable roam42.smartBlocks.activeWorkflow.blockContents holds the contents of the current block being process from the workflow. The JavaScritpt developer can read and write to this variable. Basically this is a way to intercept the current text in the block being processed without having to read or modify the DOM.

roam42.smartBlocks.activeWorkflow.name

Contains the name of the currently (or last run) workflow

roam42.smartBlocks.activeWorkflow.UID

Contains the parent block reference UID of the workflow that currently (or last run)

roam42.smartBlocks.activeWorkflow.startingBlockTextArea

The HTML element ID of the block from which the workflow was started

roam42.smartBlocks.activeWorkflow.startingBlockContents

The text of the block from which the workflow was started

roam42.smartBlocks.activeWorkflow.currentSmartBlockBlockBeingProcessed

Contains text from the current block in the workflow before being processed (useful if you want to see the context of the entire block)

roam42.smartBlocks.activeWorkflow.currentSmartBlockTextArea

the HTML Element ID of current point of where the workflow is going to insert text at finish

roam42.smartBlocks.activeWorkflow.focusOnBlock

If focus command was used, this contains the HTML Element ID of the block that will be focused upon completion

roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(outputBlock);

Call this command to output additional blocks after the current block finishes. This can be called multiple times to output multiple blocks

Parameters:

outputBlock - string of text to be inserted into the next block