Ensuring time is logged before closing ticket in JIRA

In order to ensure that the time spent on a task in JIRA has been logged before closing it, you can add this small script below as a validator in the “Close ticket” workflow transition.

The script will check if either the task or it’s subtasks (if exist) have time logged. If one or more have the time logged, it will allow closing the ticket.

 

To add this validator, you will need the Script Runner plugin installed.

 

1. Go to JIRA administration screen

2. Select Workflows

3. Select the project’s workflow that you would like to enforce time logging.

4. Edit the workflow

5. Edit the “Close ticket” transition

6. Add a new validator (you should select a script validation)

7. Paste the Groovy script below into the script text box:

Script workflow function : Simple scripted validator : Checks script: 
import com.atlassian.jira.ComponentManager

# get the work time logged on this issue
def timeWorked = issue.getTimeSpent()
if (timeWorked == null) timeWorked = 0

# get the sum of time logged on the sub-tasks for this issue (if any):
def subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = subTaskManager.getSubTaskObjects(issue)
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
  subTasks.each {
    if (it.getTimeSpent() != null) {
      timeWorked += it.getTimeSpent()
    }
  }
}
# return the result to JIRA - true if time has been logged on this ticket or it's sub-tasks
timeWorked > 0

8. Save the new validator and publish the workflow.

9. Done!

One thought on “Ensuring time is logged before closing ticket in JIRA

  1. PCSJA

    Hello!

    I don’t know if you may help me. I need to prevent blocked issues from being started/resolved if their blockers are unresolved. I’m using script runner.

    Tried to do that with simple scripted validator but it didn’t work:

    issueFunction in linkedIssuesOf(“status = unresolved”, blocks)

    Do you know how I can make it work with linkedIssuesOf? Is there any other way to do that?

    Thanks in advance.

    Reply

Leave a Reply to PCSJA Cancel reply

Your email address will not be published. Required fields are marked *