In my defect tracker, there is a field "Is Valid Defect".
Field have two options "Yes", "No".
On selection of "Yes", I want to have a counter "Valid Defect Counter" to show, that how many times defect field was selected "Yes".
Please guide.
Note : JEP field not helping, since that counts all changes in a field.
Hey @Ashish Pandey, I would say that you can achieve this in several different ways, i.e., behaviours, custom listeners, scripted field, etc. Even for each one of these options, I believe that there are many alternatives to implement this.
That said, I can share an option using a custom listener so that you can test it on your side and improve it as well.
You can select your project and Issue Updated as the event to fire on. In this case, I'm using a text field as an example for your "Valid Defect Counter" but it would be more appropriate to use a number field in which you would need to update a few things here and there.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Is Valid Defect"}
if (change && "${change.newstring}" == 'Yes') {
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Valid Defect Counter"}
def changeHolder = new DefaultIssueChangeHolder()
int counter = 1
if (tgtField.getValue(issue)) {
counter = (tgtField.getValue(issue) as Integer) + 1
}
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField),counter.toString()),changeHolder)
}
Cheers
IL.
Based on your guidance, I tried something different.
I used the custom script during transitions, and that is working for me.
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField validDefectField = customFieldManager.getCustomFieldObject("Valid Defect");
MutableIssue issue = issue
long srcField_val = 0
if(issue.getCustomFieldValue(validDefectField)!=null)
{
if(issue.getCustomFieldValue(validDefectField).toString()=="Yes")
{
def validDefectCounterField = customFieldManager.getCustomFieldObject("Is Valid Defect Counter")
srcField_val = issue.getCustomFieldValue(validDefectCounterField) as long
srcField_val = srcField_val + 1
def tgtField = validDefectCounterField
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), srcField_val.toDouble()),changeHolder)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.