---
title: "Add commands and actions to states"
slug: "add-commands-and-actions-to-states"
abstract: "How to add actions and commands to states as well as actions to commands, and how to define the final state."
---
# Add commands and actions to states

You can add actions and commands to states, and you can also add actions to commands.

## Add a command to a state

To add a command to a state:

1. Click the *Product Review* workflow.
2. Right-click the *Draft* state, then click **Insert**, **Command** and name the new command *Submit*.

    ![Add a command named Submit to the Draft state.](https://doc.sitecore.com/api/markdown-image/xp/en/developers/103/sitecore-experience-manager/images/XM-Create_cmd.png)

3. Click the *Submit* command, and select **Awaiting Approval** in the **Next state** field.

    ![Set the Next state field of the Submit command to the Awaiting Approval state.](https://doc.sitecore.com/api/markdown-image/xp/en/developers/103/sitecore-experience-manager/images/XM-Set_nxt_state.png)

Now, create the following commands under the *Awaiting Approval* state by repeating step 1-3.

- *Approve* with **Next state** set to **Approved**.
- *Reject* with **Next state** set to **Draft**.

## Add an action to a state or command

To add an action to a state or command:

1. Click the *Product Review* workflow, the *Awaiting Approval* state.
2. Right-click the *Approve* command, then click **Insert**, **Action**, and name the new command *Validation Action*.

    ![Add a Validation Action action to the Approve command.](https://doc.sitecore.com/api/markdown-image/xp/en/developers/103/sitecore-experience-manager/images/XM-Create_validtn_actn.png)

3. Click the *Validation Action* action and enter `Sitecore.Workflows.Simple.ValidatorsAction, Sitecore.Kernel` in the **Type** field. Enter `Warning` in the **Max Result Allowed** field.

    ![The Validation Action item in the content tree](https://doc.sitecore.com/api/markdown-image/xp/en/developers/103/sitecore-experience-manager/images/XM-Conf_validtn_actn.png)

4. Fill out the **Result** fields with the messages you want a user to see in case of validation errors, such as “You cannot approve an item with validation errors”.

In a similar way, add an action named *Auto Publish* to the *Approved* state but enter `Sitecore.Workflows.Simple.PublishAction, Sitecore.Kernel` in the **Type** field and `deep=1&amp;smart=1` in the **Parameters** field.

![Create an Auto Publish action under the Approved state.](https://doc.sitecore.com/api/markdown-image/xp/en/developers/103/sitecore-experience-manager/images/AX-Create_auto_publsh_actn.png)

## Define the final state

To define the final state, click the state you want to be the final state in your workflow and select the **Final** checkbox.

![Select the Final checkbox in the final state.](https://doc.sitecore.com/api/markdown-image/xp/en/developers/103/sitecore-experience-manager/images/XM-Set_final_state.png)

In this example, you can only publish items that are in the *Approved* state.