I have a custom field called "Goal Date Type" that has the values of "Ambition", "Target", and "Committed". I want to be able to list the items that have changed from either "Ambition" or "EMPTY" to "Target" or "Committed". As far as I can tell, the only access I have to changes like this are with status changes. So I suspect I need to have a date set when this change occurs. I have JMCF that I am sure would be able to do this but I am not very sure how to do the comparison in the groovy script portion. Any ideas would be very helpful, thanks.
Hi Joe,
You can create a Calculated Date time field with a Groovy script similar to this:
if(!!issue.getFieldHistory("Goal Date Type") && issue.getFieldHistory("Goal Date Type")[-1].fromString == "Ambition" && issue.getFieldHistory("Goal Date Type")[-1].toString == "Target")
return issue.getFieldHistory("Goal Date Type")[-1].created
Note, without a reindex the new value is not displayed in the searches and statistics but only the issue view. So to be able to use this field in the searches, you will need to perform a re-index after you update the custom field value.
Regards,
Radhika
Thanks. I assume you don't have to reindex it every time, just the once correct? Also, If I wanted to do Target or Committed, what would that look like?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, Joe. Just once, when you change the value of the custom field. Do you mean Target to Committed? Just replace the values in the script
if(!!issue.getFieldHistory("Goal Date Type") && issue.getFieldHistory("Goal Date Type")[-1].fromString == "Target" && issue.getFieldHistory("Goal Date Type")[-1].toString == "Committed")
return issue.getFieldHistory("Goal Date Type")[-1].created
Regards,
Radhika
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the feedback. I am actually meaning Target or Committed. Basically I want the date to be set if the goal is changed from empty or Ambition to Target or Committed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Radhika
It is working if the Goal Date Type has been set but if it hasn't been set I get the following error:
java.lang.ArrayIndexOutOfBoundsException: Negative array index [-1] too large for array size 0Stack trace:org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport.normaliseIndex(DefaultGroovyMethodsSupport.java:110) org.codehaus.groovy.runtime.DefaultGroovyMethods.getAt(DefaultGroovyMethods.java:7871) org.codehaus.groovy.runtime.dgm$293.invoke(Unknown Source) org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:244) org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127) script1581969413642307197750.run(script1581969413642307197750.groovy:2)
Here is my change to the script.
if(!!issue.getFieldHistory("Goal Date Type") && issue.getFieldHistory("Goal Date Type")[-1].fromString == "Ambition" && issue.getFieldHistory("Goal Date Type")[-1].toString == "Target" || "Committed")
return issue.getFieldHistory("Goal Date Type")[-1].created
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joe,
It has to be:
if(!!issue.getFieldHistory("Goal Date Type") && issue.getFieldHistory("Goal Date Type")[-1].fromString == "Ambition" && (issue.getFieldHistory("Goal Date Type")[-1].toString == "Target" || "Committed"))
return issue.getFieldHistory("Goal Date Type")[-1].created
Regards,
Radhika
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.