Update Custom Field Value with Version Release Date

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
Accepted answer

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.

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

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

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.

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);

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.

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".

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

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.

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?

@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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

412 views 0 3
Read article

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