# Task Assignee

This workflow automatically sets the assignee of an issue when the state changes to In Progress.

| Name | @jetbrains/youtrack-workflow-task-assignee |
| Auto-attached | no |
| Modules |  [Assign issue to current user when state changes to in progress](#set-assignee) (on-change rule)  |

## Use Case

This workflow helps you automatically set the assignee of an issue when the state changes to In Progress. This workflow is useful when you work with a agile board. The user who pulls an unassigned issue to start work on it is automatically set as the assignee.

## Modules

When the state of an issue is set to In Progress, this rule checks for a value in the Assignee field. If the field is empty, the currently logged-in user is set as the assignee.

### Assign issue to current user when state changes to in progress

```JAVASCRIPT
const entities = require('@jetbrains/youtrack-scripting-api/entities');

exports.rule = entities.Issue.onChange({
    title: 'Assign issue to current user when state changes to in progress',
    guard: (ctx) => {
        return ctx.issue.fields.becomes(ctx.State, ctx.State.InProgress) && !ctx.issue.fields.Assignee;
    },
    action: (ctx) => {
        ctx.issue.fields.Assignee = ctx.currentUser;
    },
    requirements: {
        State: {
            type: entities.State.fieldType,
            InProgress: {
                name: 'In Progress'
            }
        },
        Assignee: {
            type: entities.User.fieldType
        }
    }
});
```

