The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Get values from linked issue ScriptRunner

RobertH
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 Champions.
March 7, 2017

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

4 votes
Answer accepted
Thanos Batagiannis _Adaptavist_
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 Champions.
March 8, 2017

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

RobertH
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 Champions.
March 13, 2017

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