Alireza
Alireza

Reputation: 6848

How to prevent open task to be closed in Youtrack workflow?

There are different states in our task like: open, in-progress, fixed, tested, closed. We need to design a workflow to prevent users from closing an opened task.

I went through the documentation an saw codes like this:

var user;
if (issue.Assignee == null) {
  user = issue.project.leader;
} else {
  user = issue.Assignee;
}

The problem is that codes like above just check for statuses. I need a way to prevent actions (like closing an open task). How should I prevent users from such actions? How to check if he is closing the task?

In the documentation it's been mentioned how to access issue fields and issue custom fields. But again the code looks like below:

if (issue.State == Open) {
    # what to do here how to check if he is closing the task?
}

How should I check he is closing the task? What should I do to tell the user you cannot close the open task?

Upvotes: 0

Views: 339

Answers (2)

Alireza
Alireza

Reputation: 6848

After a lot of working with the code I found the solution:

rule check open state

when issue.State.becomes({Open}) {
    assert issue.State.oldValue == {Submitted}: "Issue needs to be in Submitted state, to make it Open" 
}

I had to use becomes in order to check whether user is opening the task, and then by using assert I'd make sure if the task is changed from Submitted state to open or not.

Upvotes: 0

Alex.V
Alex.V

Reputation: 2116

  1. Be aware that either in a when clause of a stateless rule or in the body of the rule you can implement something like State != null && !State.isResolved && (State.oldValue != null && State.oldValue.isResolved)
  2. To prevent an issue from being changed, use assert

Upvotes: 1

Related Questions