How can I add a counter for ReOpen issues?

Fernando Gutierrez September 7, 2017

I already create a custom field, then I went to my Worflow and into the transaction in which the issue pass from status "Done" to "Reopen" I want that the Custom Field increase the value, in this way I can have a counter for ReOpen Issues.

The problem is that I don't now the function that I can use to set the current value of the field and then increase it by one.

Do you know if there is a function that can do that? I mean establish a PostFunction into the transaction and establish the value to the Custom Field like  "currentValue() + 1"

2 answers

1 vote
Arbi Dridi
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 16, 2020

This is possible through a ScriptRunner post-function written in Groovy.

Assuming the name of your custom field is "Reopen Count", you can use something similar to this: 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def reopenCountField = customFieldManager.getCustomFieldObjectByName("Reopen Count")
def reopenCountVal = issue.getCustomFieldValue(reopenCountField)

if (reopenCountVal != null) {
    reopenCountVal += 1
}
else {
    reopenCountVal = 1 as double
}

issue.setCustomFieldValue(reopenCountField, reopenCountVal)

A few things to keep in mind: 

  1. The post-function should be placed before Update change history for an issue and store the issue in the database so the change can be persisted. 
  2. The Reopen Count field should not be visible in the issue edit screen because you don't want people to be able to edit it manually.

Source: 

0 votes
Arthur Mack
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 7, 2017
Ashley Kim June 28, 2018

Does this add-on work ?

I've tried but it doesn't seem to count it. 

Anyone who tried it? 

Ashley Kim June 28, 2018

I figured it out.. it counts status change from "DONE" to "In Progress" or "To Do". 

In my workflow, Reopened status("To Do") can be changed from "In Progress" or "Done", and that was why it didn't work for me.. because it does NOT count "In Progress" to "To Do" 

Suggest an answer

Log in or Sign up to answer