> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Define task Spring beans

> How to define Spring beans for custom legacy workflow task actions in Atoti Limits, using WorkflowTaskActionDTO to create UI buttons that execute tasks or display input field popups on submission

## Overview

A custom workflow task action is a `WorkflowTaskActionDTO` bean. Each bean renders a button in the UI. Build it with its builder:

| Builder method | Description |
| - | - |
| `name` | The label of the button. |
| `taskName` | The user task the action executes. It must match the user task name in the BPMN process. |
| `style` | Optional CSS style of the button. |
| `enabled` | Whether the button is enabled. Defaults to `true`. |
| `taskInputFields` | Optional input fields to show in a popup before the action executes. See [Popup with execution action](#2-popup-with-execution-action). |

Each input field is a `WorkflowTaskActionInputField`, with a `label`, a `taskVariable` that links it to a workflow variable, an
`inputType` (`SELECT`, `TEXT`, `LINK`, `CHECKBOX` or `ATTACHMENTS`), and optionally `required`, `options` (for `SELECT`) and
`defaultValue`.

## Define the beans

Depending on the type of `WorkflowTaskActionDTO` supplied to the UI, it will render a button that on clicking will either:

* Execute an action
* Show a popup for submission and then execute an action

### 1. Execution only action

The simplest instance of a `WorkflowTaskActionDTO` will look as follows:

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
    @Bean
    public WorkflowTaskActionDTO approveTaskButtonWorkflowAction(){
            return WorkflowTaskActionDTO.builder()
                .name("Approve")
                .taskName("APPROVED")
                .build();
    }
```

In this case, a button will appear on the UI with the label **Approve** and when clicked, it will submit a response to the server to execute the task specified by the task key “APPROVED”.
For more information on how the task is executed see [Executing the Java Task](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/extend/custom-legacy-workflow/custom-workflow-tasks/custom-workflow-action-java-code.md).

### 2. Popup with execution action

A more complex instance of a `WorkflowTaskActionDTO` will specify input fields to be rendered in the UI, updated and submitted to the server.
It can also provide an `defaultValue` for fields, which will pre-populate the input field in the UI. Example:

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
    @Bean
    public WorkflowTaskActionDTO reviewBreachTaskButtonWorkflowAction() {
        WorkflowTaskActionInputField<String> classificationField = WorkflowTaskActionInputField.<String>builder()
            .label("Classification")
            .taskVariable("classification")
            .required(true)
            .inputType(WorkflowVariableType.SELECT)
            .options(List.of("Unclassified", "Technical Issue", "True Breach", "New Trade", "Late Trade", "Market Moved"))
            .defaultValue("Unclassified")
            .build();

        WorkflowTaskActionInputField<String> riskCommentField = WorkflowTaskActionInputField.<String>builder()
            .label("Risk comment")
            .taskVariable("riskComment")
            .inputType(WorkflowVariableType.TEXT)
            .build();

        return WorkflowTaskActionDTO.builder()
            .name("Review")
            .taskName("REVIEW")
            .taskInputFields(List.of(classificationField, riskCommentField))
            .build();
    }
```

In this example, we define two input fields: `Classification` and `Risk comment`, with the following properties:

* `Classification` is required, so the form may not be submitted until its value is filled. `Risk comment` is not specified as required, so it defaults to false.
* `Classification` has input type `SELECT`, so the options listed will be available in a dropdown.
* `Risk comment` has input type `TEXT`, so a text field will appear requesting input.

## Import the beans

Once defined, the beans can then be imported into the Atoti Limits project. A nice convention is to have one `@Configuration` file per workflow, and to import these into a parent `@Configuration`.
Then, this one parent `@Configuration` can be [imported to the project](../../../extend#import-spring-beans-into-the-project).

For example:

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
@Configuration
@Import({
        MyFirstWorkflowTaskActionsConfig.class,
        MySecondWorkflowTaskActionsConfig.class
})
public class MyWorkflowTaskActionsConfig {
}
```
