--- alias: user-guide-automation-business-scenarios-building-structure-step-script-workflowbuilder tags: - automation - connect iot description: "This documentation details a class for constructing and managing automation workflows with configurable task settings" --- # WorkflowBuilder !!! note This is advanced documentation regarding a scope that can be accessed when executing a step of type `Script`. The `WorkFlowBuilder` class is used to construct and manage workflows comprising automation tasks. It provides methods for adding tasks, managing workflows, and handling settings, inputs, outputs, and branches. Currently, only supports `ControlFlow`. ## Public Methods ### reset === "Declaration" `reset()` === "Description" Initializes a new `WorkflowControlFlow` instance, effectively clearing any existing workflow data. === "Returns" `void` === "Example" ### loadDefaultATLs === "Declaration" `loadDefaultATLs()` === "Description" Retrieves and stores default versions of Automation Task Libraries (ATLs), caching task metadata for later use. === "Returns" `Promise` === "Example" ### addRootTask === "Declaration" `addRootTask()` === "Description" Creates and adds a root task to the workflow, generating task metadata as needed. === "Parameters" - `packageName: string` - Name of the package containing the task. - `taskName: string` - Name of the task. - `settings: any` - Configuration settings for the task. - `inputs: any[]` - Input ports for the task. - `outputs: any[]` - Output ports for the task. - `branches?: Branch[]` - (Optional) Associated branches. - `caption?: string` - (Optional) Task caption. - `driver?: string` - (Optional) Driver information. - `packageVersion?: string` - (Optional) Version of the package. - `expressions?: Expression[]` - (Optional) JSONata expressions for dynamic behavior. === "Returns" `Promise` - The created root task. === "Example" ```ts let rootTask = (await this.workflowBuilder.addRootTask( "@criticalmanufacturing/connect-iot-controller-engine-core-tasks", "driverEvent", undefined, undefined, undefined, undefined, undefined, driverAlias )); ``` ### addTask === "Declaration" `addTask()` === "Description" Adds a task to a specific branch of a root task in the workflow. === "Parameters" - `rootTaskId: string` - ID of the root task. - `branchName: string` - Name of the branch where the task will be added. - `packageName: string` - Name of the package containing the task. - `taskName: string` - Name of the task. - `settings: any` - Configuration settings for the task. - `inputs: any[]` - Input ports for the task. - `outputs: any[]` - Output ports for the task. - `branches?: Branch[]` - (Optional) Associated branches. - `caption?: string` - (Optional) Task caption. - `driver?: string` - (Optional) Driver information. - `packageVersion?: string` - (Optional) Version of the package. - `expressions?: Expression[]` - (Optional) JSONata expressions for dynamic behavior. === "Returns" `Promise` - The created task. === "Example" ```ts await this.workflowBuilder.addTask( rootTaskId, "handler", "@criticalmanufacturing/connect-iot-controller-engine-core-tasks", "logMessage", { message: "New File Event" } ); ``` ### getWorkflow === "Declaration" `getWorkflow()` === "Description" Retrieves the current workflow and resets the builder. === "Returns" `WorkflowControlFlow` - The current workflow instance. === "Example" ```ts const controllerSetupWorkflow = { automationController: `${this.answers.integrationName} Controller`, name: `Setup`, displayName: `Setup`, isFile: false, workflow: this.workflowBuilder.getWorkflow(), order: 1 }; ``` ### getSettings === "Declaration" `getSettings()` === "Description" Extracts settings from the provided input and formats them for use in branches. === "Parameters" - `settings: any` - Raw settings data to be processed. === "Returns" `any` - Processed settings data.