Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need a custom field that increments by 1 every time the issue goes to a particular status

Conrad Azzopardi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 22, 2019

Hi all, I need to count whenever issues pass through a particular status (test failed for example).

I've looked at this solution (https://community.atlassian.com/t5/Jira-questions/Need-a-custom-field-that-updates-the-value-with-an-1-increment/qaq-p/901418) but the problem with this is it keeps the number across all issues, not per issue.

Any one can help me with this (as clearly I'm not that good at groovy scripting)?

Yes I do have scriprunner plugin installed.

1 answer

1 accepted

1 vote
Answer accepted
Deleted user August 22, 2019

If you have the JMWE (Jira Misc. Workflow Extension) it's pretty easy. On the transition flow that goes into the status you want to track, add a post function and use the "Increase value of field" option. This assumes you have created a field to use.

We use this approach to track how many times an issue goes into the "Reopen" status.

Screen Shot 2019-08-22 at 9.21.48 AM.png

Conrad Azzopardi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 22, 2019

Unfortunately we do not use that addon, as we opted for JSU (which is quite similar).

 

For anyone wondering, managed to do this through scriprunner. Upon further research found a similar question, and had to modify a bit the code to work for me. Below is the code if anyone is interested:

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue;


DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = customFieldManager.getCustomFieldObjectByName("Your Custom Field");

Double currValue = (Double)cf.getValue(issue);
if (currValue == null) {
currValue = 0;
}
Double newValue = currValue+1;

cf.updateValue(null, issue, new ModifiedValue(currValue,newValue), changeHolder);

P.S. for this to work, the Your Custom Field needs to be type number, not text :) 

Suggest an answer

Log in or Sign up to answer