Forums

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

ScriptRunner: set Target Start and Target End date (Portfolio / Advanced Roadmap fields)

Patrick van der Rijst
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.
October 14, 2020

I have an event listener on the SprintUpdatedEvent, which I want to use to update all the issues in the sprint having the sprint start and end date to reflect in the fields Target Start and Target End provided by Portfolio.

 

Since this operation may take a while, I'm starting a new thread to complete this, so the UI won't freeze for the end user until this is completed. I'm aware of the drawback that some users may see incorrect data while browsing issues when this job is running.

What I notice is that I'm running into exceptions updating this field, only when doing it from a new thread. If I update the issue via the Scriptconsole or without a thread (having the UI freeze), no errors / stacktraces are thrown.

 

When I use self created custom fields of type Date picker it does complete without errors, while running this into a thread.. it makes no sense.. 

 

I want to avoid having yet another listener on the IssueUpdatedEvent that when my own custom field is set, it tries to update the Target Start / Target End field..

 

Thread.start("ScriptRunnerUpdateIssuesInSprint") {
jtlu.preCall()
try {
// retrieving the user here in case it would get lost outside of the thread
ApplicationUser user = userManager.getUserByName("jira-admin")

...
issue.setCustomFieldValue(cfTargetStart, new Date(event.sprint.startDate.getMillis()))
issue.setCustomFieldValue(cfTargetEnd, new Date(event.sprint.endDate.getMillis()))

// another try / catch so it won't stop the thread
...
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false) 

} catch(Exception ex) {
log.error ex
} finally {
jtlu.postCall(log)
}


## Stacktrace
[c.o.scriptrunner.runner.ScriptBindingsManager] ## stacktrace [com.google.common.base.Preconditions.checkArgument(Preconditions.java:127), com.atlassian.jira.entity.property.BaseEntityPropertyService.setProperty(BaseEntityPropertyService.java:96), com.atlassian.jira.entity.property.DelegatingEntityPropertyService.setProperty(DelegatingEntityPropertyService.java:41), jdk.internal.reflect.GeneratedMethodAccessor2373.invoke(Unknown Source),

I've tried various ways in updating the field, customField.setValue or using the issueService instead, all with the same result. 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Atlassian, Team '25 Europe, Atlassian conference, AI-powered teamwork, Atlassian events, keynote speakers, Barcelona tech conference, Atlassian Williams Racing, Carlos Sainz, Jenson Button, Mike Cannon-Brookes, Anu Bharadwaj, Atlassian Rovo

Atlassian Williams Racing is coming to Team '25 Europe 🏎️

Discover the teamwork and precision behind success on and off the track. See how this high-performing team makes the impossible possible. Be one of the first 100 customers to register for a chance to win 2 tickets to an Atlassian Williams 2026 race.

Register now
AUG Leaders

Atlassian Community Events