# Workflow.execute()
[EN] Source: https://mastra.ai/reference/legacyWorkflows/execute

Executes a workflow with the provided trigger data and returns the results. The workflow must be committed before execution.

## Usage Example

```typescript
const workflow = new LegacyWorkflow({
  name: "my-workflow",
  triggerSchema: z.object({
    inputValue: z.number(),
  }),
});

workflow.step(stepOne).then(stepTwo).commit();

const result = await workflow.execute({
  triggerData: { inputValue: 42 },
});
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "options",
      type: "ExecuteOptions",
      description: "Options for workflow execution",
      isOptional: true,
      properties: [
        {
          name: "triggerData",
          type: "TriggerSchema",
          description: "Input data matching the workflow's trigger schema",
          isOptional: false,
        },
        {
          name: "runId",
          type: "string",
          description: "Optional ID to track this execution run",
          isOptional: true,
        },
      ],
    },
  ]}
/>

## Returns

<PropertiesTable
  content={[
    {
      name: "WorkflowResult",
      type: "object",
      description: "Results from workflow execution",
      properties: [
        {
          name: "runId",
          type: "string",
          description: "Unique identifier for this execution run",
        },
        {
          name: "results",
          type: "Record<string, StepResult>",
          description: "Results from each completed step",
        },
        {
          name: "status",
          type: "WorkflowStatus",
          description: "Final status of the workflow run",
        },
      ],
    },
  ]}
/>

## Additional Examples

Execute with run ID:

```typescript
const result = await workflow.execute({
  runId: "custom-run-id",
  triggerData: { inputValue: 42 },
});
```

Handle execution results:

```typescript
const { runId, results, status } = await workflow.execute({
  triggerData: { inputValue: 42 },
});

if (status === "COMPLETED") {
  console.log("Step results:", results);
}
```

### Related

- [Workflow.createRun()](./createRun)
- [Workflow.commit()](./commit)
- [Workflow.start()](./start)


---
title: "Reference: Workflow.if() | Legacy Workflows"
description: "Documentation for the `.if()` method in Mastra workflows, which creates conditional branches based on specified conditions."
---