Forums

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

Is there a way to set a date using JMCF when a custom value changed?

Joe Harmon
Contributor
February 12, 2020

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.

1 answer

0 votes
Radhika Vijji _Innovalog_
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 12, 2020

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

Joe Harmon
Contributor
February 13, 2020

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?

Radhika Vijji _Innovalog_
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 13, 2020

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

Joe Harmon
Contributor
February 13, 2020

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.

Joe Harmon
Contributor
February 17, 2020

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

Radhika Vijji _Innovalog_
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 17, 2020

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

Joe Harmon
Contributor
February 18, 2020

Yep, that took care of it.  Thanks again.

Suggest an answer

Log in or Sign up to answer