Forums

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

How do I retrieve SOURCE Issue object of cloned issue in Script Runner post-function?

nnallusamy September 1, 2020

Hi, 

 

I want to distinguish Clone operation and clear certain field value through Script Runner custom post-function script. 

How can I get the source issue object and confirm the issue is created by cloning (not created originally)? 

I have tried using transientVars["sourceIssue"].key. But It returns null pointer. 

 

Thanks

1 answer

0 votes
Mathis Hellensberg
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.
September 1, 2020

Hi @nnallusamy

If you are in the context of the cloned issue, you should be able to retrieve it by looking at outward linked issues that uses the 'Cloners' default issue linking. Something like:

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

def issueLinkManager = ComponentAccessor.issueLinkManager
def sourceIssues = issueLinkManager.getOutwardLinks(issue.id)
def sourceIssueObjects = []

// There could theoretically be more than one.
sourceIssues.each() { issueLink ->
if (issueLink.issueLinkType.name.equals("Cloners")) {
sourceIssueObjects.add(issueManager.getIssueObject(issueLink.destinationId))
}
}

return sourceIssueObjects


 This is just from the top of my head. I haven't tried to run it in a post-function, but I hope it helps :)

nnallusamy September 1, 2020

Hi @Mathis Hellensberg , Thanks for the response. 

def sourceIssues = issueLinkManager.getOutwardLinks(issue.id)

sourceIssues returns EMPTY [] always since I am adding this script in Create transition which is 1st step the workflow. 

I am also adding this at the end in the post-function list (even after re-indexing step). Still, It returns EMPTY / null always. 

Don't know what else to do. 

nnallusamy September 1, 2020

Hi @Mathis Hellensberg 

def sourceIssues = issueLinkManager.getOutwardLinks(issue.id)

sourceIssues  always return EMPTY list since I am adding it on Create transition which is the 1st step in the workflow. 

Also, I have added the post-function script at the end (even after re-indexing step)

 

It still returns EMPTY always. 

Don't know what else to do.

Mathis Hellensberg
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.
September 1, 2020

Hmm after I checked, it seems I'm having the same problem.

I tried using a doAfterCreate callback, which doesn't seem to work either.

I hope someone else can figure it out.

Suggest an answer

Log in or Sign up to answer