Get values from linked issue ScriptRunner

I'm trying to inherit values when creating a linked issue, primarily the assignee since this can't be set in an issue collector, per Atlassian's documentation.  

I've added this into the workflow scripted post function to no avail:

import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
    def linkedIssue = issueLink.destinationObject
    issue.assignee = linkedIssue.getAssignee()
}

JIRA doesn't like that and won't let me use the workflow transition on issues with that function in place.  Error says:

Property 'issueLink' not found

It seems that you have tried to perform an illegal workflow operation.

 

I'm open to other alternatives, but scriptRunner just seemed to be the best route without sinking more money into add-ons.  

1 answer

1 accepted

Hi Robert,

You can use a script listener that will listen for Issue Created events and use as a script the following 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issue = event.issue as MutableIssue

def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueInputParameters = issueService.newIssueInputParameters()

// this is in question since there can be more than one issues linked with a different assignee each one
def assigneeToSet = ComponentAccessor.getIssueLinkManager().getLinkCollectionOverrideSecurity(issue)?.allIssues?.getAt(0)?.assignee

issueInputParameters.with {
    projectId = issue.projectId
    summary = issue.summary
    issueTypeId = issue.issueTypeId
    reporterId = user.name
    assigneeId = assigneeToSet?.key
}

def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)
assert !validationResult.errorCollection.hasAnyErrors()

def issueResult = issueService.update(user, validationResult)
log.info "Issue updated: ${issueResult.issue}"

Of course you can edit the script above to use it as a Post function.

The main question here is what is happening if you create an issue with other 2 linked issues that each has a different assignee. Whom are you going to add ? 

In the example above I assume that you will get the assignee of the first issue. 

Please let me know if this does the trick.

regards, Thanos

That appears to be working for me, Thanos.  Thank you very much.  

In regards to your question with the issue links and potentially having more than one, we're actually creating the issues from JIRA issues, using an issue collector which sets an individual link in the background so, in theory, we shouldn't ever get one with multiple links.  We're stretching the systems legs to use it for assets and their change requests.  smile 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

101 views 0 1
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you