It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to use ScriptRunner to update Issue Due Date based on fixVersion release Date

Hello,

I have been programming for years but am new to Jira and ScriptRunner.

Sometimes we have to change a versions release date. When I update the fix version release date I want all the issues associated with that version to have updated due dates so that their due date is the new fix version release date.

I found the related article about this topic from 2017 but I don't think it is using script runner and the syntax did not line up with what I am seeing.

Related article: https://community.atlassian.com/t5/Jira-questions/Set-Issue-Due-Date-based-on-fixVersion-release-Date-with-Script/qaq-p/678889

Any help or pointers will be greatly appreciated.

Thanks,

Nathan

 

Here is my  pseudo-code plan.

1. Use Script Listener to trigger when release date is updated.

2. Get version release date.

3. For each issue with a given fix version update issue due date in a similar way to how I did it below.

Is this a good plan?

 

help4.jpg

What I'm trying to do.. 

help3.jpg

 

1 answer

1 accepted

0 votes
Answer accepted
Leo Community Leader Oct 25, 2019

Hi @Nathan Walker,

I would use JQLsearch in listener to fetch all issues affected by the event version/release

The listener should be mapped to "VersionUpdatedEvent"

And the below script will update all issues's Due Date with version's Release Date automatically 

import com.atlassian.jira.event.project.VersionUpdatedEvent
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.IssueService
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.event.type.EventDispatchOption

def appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
def log = Logger.getLogger("Jira Log")
log.setLevel(Level.DEBUG)

def name = event.getVersion().getName()
def date = event.getVersion().getReleaseDate()
def jqlSearch = "fixVersion = \"${name}\""

SearchService.ParseResult parseResult = searchService.parseQuery(appUser, jqlSearch)
if(parseResult.isValid())
{
def searchResult = searchService.search(appUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}

issues.each{ issue ->
issue.setDueDate(new java.sql.Timestamp(date.getTime()))
issueManager.updateIssue(appUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}else {
log.error("Invalid JQL: " + jqlSearch)
}

 

you can remove if there is any unwanted packages imported, I didn't check that

 

BR,

Leo

Thank you @Leo  for the response! 

I'm still learning some basics. I am looking through documentation trying to lean.

Am I  even doing it in the right place? Can I run it in this window like this?

It is not finding the imports. I removed them and I still get a "unable to resolve class SearchService.ParseRusult error. 

Thanks again.

help5.jpghelp6.jpghelp7.jpg

Leo Community Leader Oct 25, 2019

Hi @Nathan Walker

It's not accepting/importing "com.atlassian.jira.bc.issue.search.SearchService

And that's the reason you are getting this error. unfortunately I never worked on cloud version. but I don't think the packages are different from server to cloud

Maybe you can refer Adaptavist's cloud documentation

BR,

Leo

Like Nathan Walker likes this

Thank you Leo.

It looks like the cloud version has less available functions at this time.

I'm still looking in to cloud documentation to see how I can update issue due dates when I update there version release date.

Here is another helpful link:  The differences between ScriptRunner for Jira Server and Jira Cloud 

Nathan

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

365 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you