Forums

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

(script) Cannot update Fix Version field of story when its Epic Link field is changed

Deleted user April 26, 2018

Hi, I'm trying to create a listener with Script-Runner plug in.

When I change the "Epic Link" field of a story I wish it will update the story's "Fix Version"

according to the new Epic it was linked to.

I wrote the following script listener (listens to "Issue Updated" event)  but it doesn't do anything.

I would greatly appreciate it if someone can point me to what's wrong with my script and/or correct it:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.link.IssueLinkManager

MutableIssue issue = (MutableIssue) event.issue

if(issue.issueType.name == "Story"){

def isEpicLinkChanged = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Epic Link"}
def issueLinkManager = ComponentAccessor.issueLinkManager
def issueManager = ComponentAccessor.issueManager

if(isEpicLinkChanged){
issueLinkManager.getInwardLinks(issue.getId()).each {IssueLink issueLink ->
if (issueLink.getIssueLinkType().getName() == "Epic-Story Link") {
Issue epicIssue2 = issueLink.getSourceObject()

issue.setFixVersions(epicIssue2.fixVersions)
issueManager.updateIssue(event.getUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}
}
}

1 answer

1 vote
Marcos Sanchez
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.
April 26, 2018

Hi,

There is an issue opened on Atlassian's JIRA (JSWSERVER-12299) that talks about that.

The problem is that when the Epic Link is changed no event is triggered, so it's not your fault.


Regards,
Marcos.

Deleted user April 28, 2018

Thank you Marcos!

Is there any known workaround to change fields automatically when Epic Link field is changed? (I guess not, but asking just in case...)

Marcos Sanchez
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.
April 29, 2018

Hi,

I don't know, I searched for something by I didn't find nothing.

Sorry about that.


Regards,
Marcos

Deepali Bagul
Contributor
November 26, 2018

Hello @[deleted], @Marcos Sanchez,

Were you able to get this work? I am facing the same issue. Thanks for your help.

Regards,

Deepali Bagul

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events