# One Vote Comment

This workflow adds a vote to an issue if the comment contains "+1".

| Name | @jetbrains/youtrack-workflow-one-vote-comment |
| Auto-attached | yes |
| Modules |  [Add vote to issue when comment contains "+1"](#vote-plus-one) (on-change rule)  |

## Use Case

This workflow helps you track the popularity of an issue by combining feedback in an issue comment with the actual votes applied to an issue.

## Modules

This module contains an on-change rule that scans the content of a comment that is added to an issue. If the comment contains the text "+1", a vote is added to the issue.

### Add vote to issue when comment contains "+1"

```JAVASCRIPT
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');
const regex = /\s|,|;|\.|\?|!/;

exports.rule = entities.Issue.onChange({
  title: 'Add vote to issue when comment contains "+1"',
  guard: (ctx) => {
    return ctx.issue.comments.added.isNotEmpty();
  },
  action: (ctx) => {
    const issue = ctx.issue;

    let index = -1;
    issue.comments.added.forEach(function(comment) {
      if (index < 0 && comment.text) {
        index = comment.text.split(regex).indexOf('+1');
      }
    });
    if (index >= 0) {
      ctx.currentUser.voteIssue(issue);
      if (issue.isChanged('votes')) {
        workflow.message('The single vote is added.');
      }
    }
  },
  requirements: {}
});
```

