A single global "context" object is available to scripts to control flow of the currently running action.

It is important to understand that cancel() and fail() will not immediately stop script, just stop any further action steps from being performed.

Example

Control Flow

// test for logical condition before continuing
if (!validationCondition) {
context.fail();
}
// code below will still run.

Retreive values

// if a "Run Workflow" step preceded this script, lets look for a result
let response = context.callbackResponses[0];
if (response) {
// Workflow returns one "result" parameter, other apps may use other values.
var result = response["result"];
if (result) {
// so something with the result
}
}

Hierarchy

  • Context

Constructors

Properties

appleScriptResponses: {
    [x: string]: any;
}

If AppleScripts run using the AppleScript object return values, they will be converted to JavaScript object and stored in this array. See AppleScript docs for details.

Type declaration

  • [x: string]: any
callbackResponses: {
    [x: string]: any;
}

If Callback URL or Run Shortcut action steps using the "Wait for response" option have been run in steps before the script step in an action, and the target app returned to Drafts using an x-success callback, this object will contain an array of objects with the parsed query parameters included in those responses, in the order they were received.

Type declaration

  • [x: string]: any
previewValues: {
    string: any;
}

If HTML Preview makes calls to Drafts.send(key, value) those values are stored in this object by key.

Type declaration

  • string: any

Methods

  • Used only when calling a Drafts action from another app via x-callback-url with a /runAction URL. Any parameters set via this method will be included as query args when calling the provided x-success parameter. As an example, the below:

    context.addSuccessParameter("a", "1");
    context.addSuccessParameter("b", "2");

    Would result in the parameters ?a=1&b=2 being added to the x-success callback.

    Parameters

    • name: string

      The name for the parameter

    • value: string

      A string value for the parameter. Do not URL encode this value, it will be encoded when added to the callback URL.

    Returns void

  • Tell the context to cancel the action at the end of the script execution. If called, at the end of the script the action will be stopped. No subsequent action steps in the action will run, and the action still stop silently - no notification banners, sounds, etc. If a message is included it will be added to the action log to explain the cancellation.

    Parameters

    • message: string

    Returns void

  • Tell the context to fail the current action. In effect this is the same as cancel() but an error notification will be shown. If a message is included it will be added to the action log to explain the cancellation.

    Parameters

    • message: string

    Returns void

Generated using TypeDoc