# Watcher by Votes

This workflow automatically sets the project owner (referenced in the code as `project lead`) as a watcher when an issue receives a specific number of votes.

| Name | @jetbrains/youtrack-workflow-watcher-by-votes |
| --- | --- |
| Auto-attached | no |
| Modules |  [Add project lead to watchers list when an issue receives 10 votes](#add-watcher) (on-change rule)  |

## Use Case

This workflow helps you automatically raise the visibility of an issue when it receives a specific number of votes. You can customise this workflow to add other users as watchers or modify the number of votes.

## Modules

When an issue receives ten votes, this rule automatically sets the project owner as a watcher for the issue.

### Add project lead to watchers list when an issue receives 10 votes

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

exports.rule = entities.Issue.onChange({
    title: 'Add project lead to watchers list when an issue receives 10 votes',
    guard: (ctx) => {
        return ctx.issue.oldValue(votes) <= 9 && ctx.issue[votes] >= 10;
    },
    action: (ctx) => {
        ctx.issue.project.leader.watchIssue(ctx.issue);
    },
    requirements: {}
});
```

