RamblingAP
RamblingAP

Reputation: 145

Displaying how often an issue has been reopen in JIRA

I'm currently running a fairly out-of-the-box JIRA setup that is live and being used.

Now I'm at a point where I would like a custom field in each bug that will display the total amount of times and issue/bug has been reopened.

There is a plugin (https://answers.atlassian.com/questions/19665/how-to-count-based-on-status-jira) that does something similar, however, I am looking for a solution that doesn't require purchasing a third-party plugin (OPS doesn't like plugins).

I've searched forums high and low and was unable to even find a good starting point. Your help is always appreciated. Thanks in advance!

EDIT: Current JIRA version: 5.2

Upvotes: 4

Views: 7022

Answers (3)

altern
altern

Reputation: 5949

My solution is to add the post-function to the 'Reopen' transition with the following code (it assumes you have Script Runner plugin installed and enabled; also you have to add custom field 'Reopen count' to the corresponding view screen):

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

def componentManager = ComponentManager.getInstance()
def customFieldManager = componentManager.getCustomFieldManager() 
def reopenCount = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Reopen count'}
def changeHolder = new DefaultIssueChangeHolder();
def reopenCountValue = issue.getCustomFieldValue(reopenCount)
if(reopenCountValue == null) reopenCountValue = 0.0d
reopenCount.updateValue(
    null, 
    issue, 
    new ModifiedValue(
        reopenCountValue, 
        ++reopenCountValue
    ), 
    changeHolder
);

Upvotes: 0

Kuf
Kuf

Reputation: 17836

Create a custom field for counting the times an issue was opened, and set it's default value to one. Then use the Behaviours Plugin to add validation script to the transitions you wish to count. In the validation script, increment the custom field and return true. should be something like:

FormField formComponent = getFieldById(fieldChanged)
FormField formUserField = getFieldByName("UserFieldA"
formUserField.setFormValue(Integer.valueOf(formUserField.getFormValue()) + 1)

If you're having trouble coding that have a look here or ask here.

An easier way would be to attack a post-function to the re-open transition using Jira Scripting Suite and use it to increment the field, but it doesn't support Jira 5.2 yet.

If you don't want to use any plugins, you can use Webhooks attached to the re-open workflow transition that will post to an URL , which in turn, will connect back using the REST API and increment that field.

Upvotes: 3

Borislav Sabev
Borislav Sabev

Reputation: 4866

A Custom field holds some information (metric, counter, misc. info, etc.) but it is not logic by itself. So the problem here is that in order to increment a (custom) field you will have to have some logic doing that. So you're left with three options:

  1. Use the plugin you're talking about
  2. Custom-build a plugin for this
  3. Use a custom-built external application utilizing the REST API that polls for changes on issues and when it detects "Reopenings" and increments the custom field's value.
  4. Manually assign this field (not really an option)

So at the end there aren't that many options that do not require resouces - development or purchasing some plugin. Usually it's best to buy a plugin because you're also buying support with that. However beware that if the plugin is not developed by Atlassian there is the possibility that it may not support future JIRA versions or it may not be compatible right after a new JIRA version release.

Upvotes: 0

Related Questions