Skip to main content

Programmatic usage

You can start a workflow from code and, if the top-level configuration defines an onReturn hook, receive a return value when the user exits the workflow with the Accept button. On a regular close, the workflow resolves to undefined.

The result flows like this:

  1. The user clicks Accept.
  2. The onReturn handler runs and calls controller.returnResult(value).
  3. Your awaited startWorkflow(...) resolves to that value.

Basic usage

import {startWorkflow} from '@datagrok-libraries/compute-api';

const result = await startWorkflow<MyReturnShape>('SomePackage:SomeWorkflow', '1.0', {});

nqName (first argument) is the workflow provider's package:function identifier. version must match a value listed in the provider's meta.versions annotation. The third argument is the initial PipelineInstanceConfig; pass {} to start with the provider's defaults.

With initial configuration

For dynamic workflows you can pre-populate the initial step list and per-step values by passing a PipelineInstanceConfig as the third argument. LSP fills in the recursive field shape.

import {startWorkflow} from '@datagrok-libraries/compute-api';
import type {PipelineInstanceConfig} from '@datagrok-libraries/compute-api';

const instanceConfig: PipelineInstanceConfig = {
id: 'some_workflow',
steps: [{
id: 'load',
initialValues: {deviceClass: 'Bioreactor Class'},
inputRestrictions: {deviceClass: 'disabled'},
}],
};

const result = await startWorkflow<MyReturnShape>(
'SomePackage:SomeWorkflow',
'1.0',
instanceConfig,
);

initialValues and inputRestrictions follow the same semantics as the script node fields of the same name. See Consistency for the meaning of restriction values.