---
title: "Assign commander from schedule | Grafana Cloud documentation"
description: "When an incident is declared without a commander, assign whoever is on call in your incident commander schedule."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Assign commander from schedule

> Note
> 
> Grafana Workflows is currently in [public preview](https://grafana.com/docs/release-life-cycle/). Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available.

When an incident is declared without a commander, assign whoever is on call in your incident commander schedule.

This Grafana Workflows blueprint is in the **Incidents** category of the Blueprints library.

## Before you begin

To use this blueprint, you need:

- Grafana IRM set up on your stack.

## Steps

Steps run in order from first to last. A step inside a switch branch runs only when Workflows chooses that branch.

Expand table

| Step                                                                | ID                  | Type                          | Description                                                                                                                                                                                        |
|---------------------------------------------------------------------|---------------------|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| No commander yet?                                                   | `no-commander-yet`  | `filter`                      | Stops the run when the incident already has a commander, for example when the person who declared it took the role. No changes needed.                                                             |
| Find the on-call commander                                          | `get-on-call`       | `irm.schedule-current-oncall` | Looks up who is currently on call in your incident commander rotation. Set `scheduleIdentifier` to the exact name of the IRM schedule, or switch `identifierType` to id and paste the schedule ID. |
| Assign commander if someone is on call                              | `assign-commander`  | `switch`                      | Assigns the first on-call user as commander, or leaves a note when nobody is on call. No changes needed.                                                                                           |
| Make on-call user the commander (branch 1 of `assign-commander`)    | `add-commander`     | `incident.add-participant`    | Gives the on-call user the commander role on the incident. No changes needed.                                                                                                                      |
| Note who was assigned (branch 1 of `assign-commander`)              | `note-assigned`     | `incident.add-note`           | Adds a timeline note saying this workflow assigned the commander. No changes needed.                                                                                                               |
| Note that nobody was on call (default branch of `assign-commander`) | `note-no-commander` | `incident.add-note`           | Records that nobody was on call so the team knows to pick a commander. No changes needed.                                                                                                          |

For the inputs and outputs of each step type, refer to [Step and trigger types reference](https://grafana.com/docs/grafana-cloud/platform/workflows/reference/step-trigger-types).

Before you turn on the workflow, customize any steps that need input from you, such as a channel ID or a schedule name. Each step’s description says what to set.

## Workflow definition

Save this definition as a YAML file to create the workflow with gcx, the Workflows API, or Terraform, or give it to a coding agent as an example. Replace *FOLDER\_UID* with the UID of the folder for the workflow. Blueprints start disabled, so finish customizing the steps before you set `enabled` to `true`. For details, refer to [Manage workflows as code](https://grafana.com/docs/grafana-cloud/platform/workflows/as-code).

YAML ![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg) Copy

```yaml
apiVersion: workflows.ext.grafana.app/v1alpha1
kind: Definition
metadata:
  name: assign-commander-from-schedule
  annotations:
    grafana.app/folder: <FOLDER_UID>
spec:
  name: Assign commander from schedule
  enabled: false
  startWhen:
    matchingRules:
      - eventNameRegex: 'grafana_irm_app\.incident\.updated'
        filter: "inputs.data.eventKind == 'incident_created'"
    schedules: []
  steps:
    - id: no-commander-yet
      type: filter
      name: No commander yet?
      description: Stops the run when the incident already has a commander, for example when the person who declared it took the role. No changes needed.
      inputs:
        condition: "resources.incident.event.incidentMembership.assignments == null || !resources.incident.event.incidentMembership.assignments.exists(a, a.role == 'commander')"
    - id: get-on-call
      type: irm.schedule-current-oncall
      name: Find the on-call commander
      description: >-
        Looks up who is currently on call in your incident commander rotation. Set
        scheduleIdentifier to the exact name of the IRM schedule, or switch identifierType to id
        and paste the schedule ID.
      inputs:
        scheduleIdentifier: ''
        identifierType: 'name'
    - id: assign-commander
      type: switch
      name: Assign commander if someone is on call
      description: Assigns the first on-call user as commander, or leaves a note when nobody is on call. No changes needed.
      branches:
        - condition: "steps['get-on-call'].outputs.count > 0"
          steps:
            - id: add-commander
              type: incident.add-participant
              name: Make on-call user the commander
              description: Gives the on-call user the commander role on the incident. No changes needed.
              inputs:
                incidentID: '${inputs.data.incidentID}'
                userID: "${steps['get-on-call'].outputs.users[0].email}"
                role: 'commander'
            - id: note-assigned
              type: incident.add-note
              name: Note who was assigned
              description: Adds a timeline note saying this workflow assigned the commander. No changes needed.
              inputs:
                incidentID: '${inputs.data.incidentID}'
                message: "The **Assign commander from schedule** workflow made ${steps['get-on-call'].outputs.users[0].username} the incident commander because they are on call."
        - steps:
            - id: note-no-commander
              type: incident.add-note
              name: Note that nobody was on call
              description: Records that nobody was on call so the team knows to pick a commander. No changes needed.
              inputs:
                incidentID: '${inputs.data.incidentID}'
                message: 'Nobody was on call in the incident commander schedule, so no commander was assigned automatically. Assign one from the incident page.'
```

## How it works

This section explains when the workflow runs and how its steps work together.

### When it runs

This blueprint starts on the `grafana_irm_app.incident.updated` event.

Its trigger filter starts a run only when this CEL expression is true:

text ![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg) Copy

```text
inputs.data.eventKind == 'incident_created'
```

### How the steps fit together

These notes cover how the steps connect and which Workflows behaviors the blueprint relies on.

- Triggers once per incident on `eventKind` `incident_created`.
- A filter step reads the auto-loaded incident’s role assignments at `resources.incident.event.incidentMembership.assignments`, where each entry has a role (for example commander) and a user, and stops the run when someone already holds the commander role, for example when the person declaring the incident took it.
- assignments is null when nobody holds a role, so the condition checks for null before calling `exists()`.
- `irm.schedule-current-oncall` looks up who is on call in the commander schedule.
- A switch assigns the first on-call user with `incident.add-participant` and records it on the timeline, and its default branch leaves a note when nobody is on call.
- Major incident kickoff also assigns a commander, as part of a larger flow for Critical incidents.
- Customize the schedule name and, to limit it by severity, add a condition on `resources.incident.event.severity` to the trigger filter.

## Next steps

- [Blueprints](https://grafana.com/docs/grafana-cloud/platform/workflows/reference/blueprints)
- [Start from a blueprint](https://grafana.com/docs/grafana-cloud/platform/workflows/build/use-blueprints)
- [Manage workflows as code](https://grafana.com/docs/grafana-cloud/platform/workflows/as-code)
- [Step and trigger types reference](https://grafana.com/docs/grafana-cloud/platform/workflows/reference/step-trigger-types)
