Can I edit field of related issue via Listener's script?

Jan Kurowski December 11, 2019

Hi!
I'm trying to add Custom Listener that would execute code after Issue Updated event occurs. The problem is that I don't know how to change linked issue's priority. 
I would appreciate any help!
 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
import com.atlassian.jira.event.type.EventDispatchOption


def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Priority"}
if (change && event.issue.issueType=="Zadanie") {
def issueManager = ComponentAccessor.getIssueManager()
def issueBNGObj= issueManager.getIssueObject(event.issue.key)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()

for(item in issueLinkManager.getOutwardLinks(event.issue.getId())){
def linkedIssue= item.destinationObject
def linkedIssueObj= issueManager.getIssueObject(linkedIssue.key)
def projName=linkedIssue.getProjectObject().name
if(projName=="Rejestr Potrzeb"){
linkedIssueObj.setFieldValue("priority", issueBNGObj.priority) // error lights up here
issueManager.updateIssue(event.user, linkedIssueObj, EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
}

1 answer

1 accepted

0 votes
Answer accepted
Alex Christensen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 11, 2019

On the line that's erroring for you:

linkedIssueObj.setFieldValue("priority", issueBNGObj.priority) // error lights up here

Try using this instead:

linkedIssueObj.setPriority(issueBNGObj.priority)

Priority is a system field, so you shouldn't need to use the .setFieldValue method, but the .setPriority() one instead. See the MutableIssue class for more methods like that.

Jan Kurowski December 12, 2019

Thanks a lot! That helped.

Suggest an answer

Log in or Sign up to answer