Forums

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

Identify a cloned issue using a workflow post function on create transition and change something

Peter Newton June 17, 2020

Hi,

I am trying to identify a cloned issue using a post-function on create step of the workflow.

If it is a clone, I will like to perform some changes in the issue(custom fields, summary, assignee)

Is it possible? Anyone knows how? I tried several variants none seems to work

Below is the clearest one, I am using scriptrunner but...not working

Any idea? This script always return something in else. The name of the link is correct, tryed uppercase, all lowercase. same result. I think I'm missing something.

import com.atlassian.jira.issue.Issue 
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent

def linkManager = ComponentAccessor.getIssueLinkManager()

if (linkManager.getOutwardLinks(issue.getId()).any {IssueLink link ->
link.getIssueLinkType().getName() == "Cloners"})
{
//do something
}else{

//nothing
}

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.
June 18, 2020

Hi @Peter Newton 

Without looking to closely at the provided script have you made sure that this post-function is the last post-function on the create transition list? Otherwise nothing is gonna work :)

Peter Newton June 18, 2020

Hi Mathias

Thanks for answering - it is the last one, after fire a issue created event

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.
June 18, 2020

Hmm this works in my console. I have comment out the issue I was using for testing purposes :)

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import org.apache.log4j.Level;

log.setLevel(Level.INFO);

def issueLinkManager = ComponentAccessor.issueLinkManager
def issueManager = ComponentAccessor.issueManager
//def issue = issueManager.getIssueObject("SD-492")

def clonedId = 10001 //Cloned

def links = issueLinkManager.getInwardLinks(issue.id)

links.each() { linkedIssue ->

if (linkedIssue.issueLinkType.id == clonedId) {

def clonedIssue = issueManager.getIssueObject(linkedIssue.sourceId)
log.info("Watch out issue with key: ${clonedIssue} is a clone!")

}

}  

 Hope it helps! :)

Peter Newton June 22, 2020

Hi Mathis,

Some-how, on my end this is not working and I'm not able to see the results of

linkedIssue.issueLinkType.id

In logs will appear only workflowopperation 

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.
June 22, 2020

Can you post a screenshot of the log and I'll take a look :)

Suggest an answer

Log in or Sign up to answer