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:
- The user clicks Accept.
- The
onReturnhandler runs and callscontroller.returnResult(value). - Your awaited
startWorkflow(...)resolves to thatvalue.
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.