Forums

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

Script to increment value of custom field in Post Validation Condition

Ian Chilvers February 25, 2014

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

2 votes
Radu Dumitriu
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.
February 25, 2014

Using JJupin, your script is:

customfield_11505 += 1;

HTH

Ian Chilvers February 25, 2014

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

Radu Dumitriu
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.
February 25, 2014

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

Ian Chilvers February 25, 2014

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?

Radu Dumitriu
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.
February 25, 2014

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
Rumceisz
Contributor
July 7, 2014

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;

0 votes
Ian Chilvers February 25, 2014

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.

0 votes
Tarun Sapra
Community Champion
February 25, 2014

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

Suggest an answer

Log in or Sign up to answer