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

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

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

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.

Thanks a lot! That helped.

Suggest an answer

Log in or Sign up to answer
TAGS

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