Source: https://support.atomicwork.com/product/enterprise-workflows/get-started/how-a-workflow-works

# How a workflow works

A workflow is a script that runs after its trigger. You describe the automation in plain language, and Service Assist writes the script, shows you the draft, and tests it before you publish. For example, you can ask for a workflow that assigns every laptop ticket to a specific agent when it's created.

## Triggers

Every workflow starts with a trigger, which decides when the workflow runs. An event-based trigger has three parts: the events that start the workflow, such as **Request is created**; who performed the event, such as the requester, an agent or an AI agent; and filters that limit it to matching records, such as requests whose subject contains "laptop". A schedule-based trigger runs the workflow at the times you set. Service Assist sets up the trigger from your description, and the trigger card in the **Builder** describes it in a sentence. See [Workflows 101](/product/enterprise-workflows/get-started/workflows-101#review-the-trigger) and [Workflow events](/product/enterprise-workflows/triggers/workflow-events).

Every step after the trigger is code. The script calls Atomicwork, for example to read or update a request, and the apps you've connected.

## Create a workflow

1. Go to **Automations > Workflow library**.

2. Pick **Event-based** for a workflow that starts on an event, or **Schedule-based** for one that runs on a schedule.

3. Select the object the workflow runs on, such as **Request**. For request and change workflows, click your workspace under the object.

4. Click **New**. Service Assist opens with a chip that shows the scope, for example "Event-based request workflows • Default workspace". For a **Change** object, **New** creates a draft workflow and opens it in the builder, with the Service Assist panel open.

5. Describe the workflow in the prompt box.

6. Answer any questions Service Assist asks, review the draft, and click **Publish** when the workflow is ready.

![Full-page Service Assist with a scope chip and a prompt box](assets/code-workflows-01-create-with-ai-assist.png)

For tips on writing a good description, answering questions and testing, see [Build workflows with Service Assist](/product/enterprise-workflows/get-started/build-workflows-with-ai-assist).

## Read the Builder

Open a workflow to see its **Builder**. The **Builder** is a read-only diagram of the steps.

The trigger card describes the trigger in a sentence, for example "When request is created by any user or AI agent, with subject containing laptop". Each step card shows a title and a one-line description that Service Assist writes. The Builder reads both from comments in the script, which Service Assist writes.

![The Builder for a workflow, with a trigger card and step cards that end at Finished](assets/code-workflows-02-builder-steps.png)

You may see these step types:

| Step                      | What it does                                                                                               |
| ------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **Condition**             | Checks a condition and branches the workflow.                                                              |
| **Switch**                | Branches into several paths, with an **Any other case** branch for everything the other paths don't match. |
| **Approval**              | Waits for a decision before the workflow continues.                                                        |
| **Wait**                  | Pauses the workflow before the next step.                                                                  |
| **Repeats for each item** | Runs the steps inside it once for each item in a list.                                                     |
| **Finished**              | Marks the end of the workflow.                                                                             |

To see the script behind the diagram, click the code icon (`</>`) on the canvas, or press **C**. The **Code** panel opens beside the diagram. Its footer shows the number of steps and lines, and has a button that copies the code.

![The Builder with the Code panel open beside the step diagram](assets/code-workflows-03-builder-code.png)

To change a workflow, ask Service Assist. See [Change a workflow](#change-a-workflow).

## If a step fails

By default, a step that fails stops the workflow. A step can also be written to handle failure in one of two ways:

- **Continue:** The later steps still run.
- **Take a different path:** A failure branch runs instead of the steps that follow.

This behavior is part of the script. To change how a step handles failure, ask Service Assist, for example: "If the Slack message fails, keep going with the next step."

## Change a workflow

To change a workflow, open it, click **Service Assist**, and describe the change in your own words in the chat box.

![A workflow open in the Builder, with the Service Assist panel open](assets/code-workflows-04-edit-with-ai-assist.png)

For prompt examples and troubleshooting, see [Build workflows with Service Assist](/product/enterprise-workflows/get-started/build-workflows-with-ai-assist).

## Track runs and versions

Each workflow page has **Overview**, **Builder** and **Versions** tabs. The header shows the published version and has a **Publish** button.

**Overview** shows the workflow's name and description, with these parts:

- **Run logs:** Every run of the workflow, which you can filter by **All**, **Success**, **Failed** or **In progress**.
- **Version details:** The status, published version, and who last modified the workflow and when.
- **Run activity:** The workflow's runs over the last week (**1W**) or six months (**6M**).
- **Other details:** The trigger type, workspace, creator and creation date.

![The Overview tab of a workflow, with run logs and side panels for version details, run activity and other details](assets/code-workflows-05-overview.png)

**Versions** shows the **Version History**, including **Published Versions**.

The more menu (⋮) in the header has **Unpublish**, **Duplicate workflow** and **Delete**.

![The more menu on a workflow page, with Unpublish, Duplicate workflow and Delete](assets/code-workflows-06-more-menu.png)

## Related articles

- [Workflows 101](/product/enterprise-workflows/get-started/workflows-101)
- [Build workflows with Service Assist](/product/enterprise-workflows/get-started/build-workflows-with-ai-assist)
- [Workflow events](/product/enterprise-workflows/triggers/workflow-events)
- [Service Assist](/product/ai-knowledge/ai-assist)
