Update Custom Field Value with Version Release Date

Ron L August 14, 2017

Hello, I'm currently using JIRA Misc Custom Fields to automatically set a custom field with the Version release date.  This works well except for the fact that the issue isn't re-indexed until the issue has been actually updated and the cache cleared.  

Can I use script-runner to get around this at all either by using its custom field or adding a listener on Version release date change to update all linked tickets?  

My goal would be to have this custom field "Release Date" updated whenever an issue's fixVersion is set OR the existing fixVersion's Release Date is udated and have it immediately re-indexed so that the new value can be queried.

1 answer

1 accepted

1 vote
Answer accepted
Joshua Yamdogo @ Adaptavist
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.
August 15, 2017

This can be accomplished fairly trivially with a scripted field in ScriptRunner.

enableCache = {-> false}
def version = issue.getFixVersions()
version.first().getReleaseDate().format("dd/MMM/yyy")

This will display the release date for the Version, assuming you only have one Version set for the issue. It will automatically update if someone edits the Version release date or changes the Version to another one.

Screen Shot 2017-08-15 at 11.34.37 AM.png

You may want to edit the format for how the date is displayed. You might need to change the searcher/template for the script field if you plan to run JQL queries against it, but that's something you'll have to play around with.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 15, 2017

Hi Joshua,

will the value be automatically updated in the JIRA index for all issues that have that Fix Version whenever the version's release date changes? That is, will a search based on that "Release Date" field return all pertinent issues after an update to the version's release date? Without manually triggering a JIRA index update?

David

Joshua Yamdogo @ Adaptavist
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.
August 15, 2017

From the testing I've done, there doesn't seem to be a problem with the JIRA index. After updating the Version's release date, I did not do any manual reindexing and did not visit any of the issues. Then, I did a JQL search based on Release Date and got the results that I expected with the new Release Date values. 

So, this solution seems to work fine. However, if there were problems with the JIRA index, I think this problem could also be trivially solved using a listener. You can set up a listener that responds to an update of the Version's release date:

Screen Shot 2017-08-15 at 12.21.30 PM.png

Ron L August 15, 2017

Hi Joshua,

I was able to use the JQL function releaseDate() to achieve the result.  I have run into an issue where I am unable to use parameters with startOfWeek() in the releaseDate() function.  For example,

fixVersion in releaseDate("after startOfWeek('+1d'))

 Is there a way to do this?  Ultimately, I want to target all release on "This Tuesday", "This Wednesday", etc.

Joshua Yamdogo @ Adaptavist
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.
August 16, 2017
Ron L August 20, 2017

Hi Joshua, I'm trying to create a scripted field to store the Release Date based on whether or not there is a fixVersion set.  It's related to the above.

Right now, I'm just trying to test this and have the following code, but it is giving me a "$datePickerFormatter.format($value)" as the result when previewing.  Any ideas why?

return new Date(5000000000000);
Joshua Yamdogo @ Adaptavist
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.
August 21, 2017

Hi Ron,

Have you taken a look at this page: https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html

There's some sample code in there about returning the correct format for a datetime field.

Does the code I supplied above not work for this use case? This code would return the Release Date if there is a fix version set.

enableCache = {-> false}
def version = issue.getFixVersions()
version.first().getReleaseDate().format("dd/MMM/yyy")

Looking forward to your response.

Ron L August 21, 2017

Hi Joshua,

When trying to run your script above and previewing, I get the following in the Result tab: "$datePickerFormatter.format($value)".

I've selected "Absolute Date Time" as the template and have also tried removing the explicit format() call, but still get the above result.

If I select "Text Field" as the template I get "22/Aug/2017".

Joshua Yamdogo @ Adaptavist
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.
August 21, 2017

Hi Ron,

Good observation. You do actually need to remove the format() method. Along with that, you need to change the searcher for the field as well. "Absolute Date Time" is the correct template, but you should go to Admin -> Custom Fields -> Edit field and change the searcher to Date Time Ranger picker.

After doing that and using this script:

enableCache = {-> false}
def version = issue.getFixVersions()
version.first().getReleaseDate()

I get this:

Screen Shot 2017-08-21 at 2.53.43 PM.png

Ron L August 21, 2017

I made the change to the field to use "Date Time Ranger Picker", but I also had to adapt the solution from another community ticket to get it to work and create a Date object.

The value now shows up, but when attempting to run a JQL query against this column where I'm using >= 2017-08-17, I'm getting issues with 2017-08-16 as a value, which doesn't make sense.

Ron L August 21, 2017

On a separate note, is it possible to return just the date or is the formatter on the template always going to return date and time?

Aisha M February 26, 2018

Joshua Yamdogo @ Adaptavist Hi Joshua, I'm fairly new to scriprunner. I am trying to implement the solution you have given above for making the release dates visible with the Fix versions. I just need to know how to accomplish this with the already existing Fix Version field.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events