Script to increment value of custom field in Post Validation Condition

I have created a Custom Field (Number) called 'Failed Count' with a default value of 0 (zero).

I want to add a Post Validator condition to the transition 'Fail', if the user selects this option from the 'In Test' status step to increment the value of the 'Fail Count' field by 1 every time it passes through this workflow path. Field is Customfield_11505 (found via looking at URL from 'Configure' option for field).

I have no idea how to code HTML, so any help appreciated.

Thanks

5 answers

Using JJupin, your script is:

customfield_11505 += 1;

HTH

Thanks Radu - I will give it a go and advise if it works.

Unfortunately, it failed ...

Unable to update custom field customfield_11505 - Failed Count in issue [RELDEMO-12].

As a thought - do I need to put this code inside some HTML - something similar to this ... (as I have said, I do not know HTML or scripting code, so this is a best guess)

<!-- @@Formula: customfield_11505 += 1; : 0) -->

Also, apologies, but I have no idea what 'JJupin' means

Don't bother. It works (believe me), this is a plugin we created for easy scripting your JIRA.

So, using the 'Update Issue Custom Field' Post Validator option - in the 'Custom Field Value' - I type ... customfield_11505 +=1; - no other code around it and no other punctutation?

I believe you're talking about another plugin (JIRA Suite Utilities plugin). In that case, refer to their help. Ours do something similar, but in a completely different way.

0 votes
Tarun Sapra Community Champion Feb 25, 2014

Doing it in a post-function might be better than trying to do it in HTML/JS.

Thanks for quick response Tarun. Yes, I want to add a Post Condition, Update Issue Costom Field - Select 'Field Count' for 'Issue Custom Field' and then add the script in the 'Custom Field Value' that increments the value by 1. It is the script that I need to put in there that I don't know how to code.

Hi,

this is my solution:

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
 
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
 
def reopened = "1"
def resolved = "5"

def prev =""
def count = 0; 

changeHistoryManager.getChangeItemsForField (issue, "status").each {ChangeItemBean item -&gt;
 
 def from  = item.from;
 def to = item.to;
 if (to.equals(reopened) &amp;&amp; resolved.equals(from))
 {
 	count++;		
 }
}
 
// NOTE: doesn't show anything if less than 60 seconds
return count as Double;

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,777 views 11 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot