In Jira Create issue in another project with Script Runner

I have few projects, A,B,C,D,E.

A is the high level project. B,C,D,E are low level project.
I need to create a postfunction on Project A, that will create a new issue on Project, based on a drop down list value in A.

For example:

drop-down list A: with value 1, 2, 3,4,5,6

If 1 was selected, after click save issue create button, clone save issue to project B, and link these two issues.

If 2 was selected, after click save issue create button, clone save issue to project C, and link these two issues.

If 3 was selected, after click save issue create button, clone save issue to project B, and link these two issues.

If 4 was selected, after click save issue create button, clone save issue to project D, and link these two issues.

If 5 was selected, after click save issue create button, clone save issue to project B, and link these two issues.

If 6 was selected, after click save issue create button, clone save issue to project E, and link these two issues.

Is there a way I can do that with script runner?

Any insight on the matter is highly appreaciated.

Kind regards

2 answers

You can do it via script runner. However, a cleaner and better way to do this is using the Bob swift add-on create on transition .

I cannot provide you a complete working script however, you can refer and try working on the below code snippet

def public CreateLinkedIssue(String ProjectName,String IssueType, String Summary, String Description){

// importing the required managers
def issueFactory = ComponentAccessor.getIssueFactory();
def issueManager = ComponentAccessor.getIssueManager();
def projectMgr = ComponentAccessor.getProjectManager();
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
def issueMgr = ComponentAccessor.getIssueManager();
def issueLinkManager = ComponentAccessor.getIssueLinkManager();

// create new issue from factory
def issueObject = issueFactory.getIssue();

//set values
issueObject.setSummary("Child :"+issue.getSummary());

//create actual issue
def child_issue= issueManager.createIssueObject(authenticationContext.getLoggedInUser(), issueObject)
Long lid=10003;
Long seq =1;
//link the issue



Hi Mizan,

I have post function code as below, will you help me take a look?

import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.ImportUtils
import com.atlassian.crowd.embedded.api.User;
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.IssueFactory;

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserManager

class TaskVersionListener extends AbstractIssueEventListener {
Category log = Category.getInstance(TaskVersionListener.class)

void workflowEvent(IssueEvent event) {
def issue = event.getIssue()
if ( issue.getIssueTypeId() == "XXXXX" ) { // The Issue Type to catch in the Listener
def projectName = "YYYYY" //Target project name

def issueMgr = ComponentAccessor.getIssueManager()
def projectMgr = ComponentAccessor.getProjectManager()
String currentUser = event.getUser().getName();
User currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentManager componentManager=ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

def issueFactory = ComponentAccessor.getIssueFactory()
def newissue = issueFactory.getIssue()
newissue.setSummary (issue.summary)
newissue.setProject (projectMgr.getProjectByName(projectName))
newissue.setIssueTypeId("JJJJ") //The ID of the target Issue Type
newissue.description = issue.description
newissue.reporter = issue.getReporter()

//Set the Project Lead of the target project as assignee of the new ticket
def project = projectMgr.getProjectObjByName(projectName)

//Copy the fields that you want
def cf = null;
//ZZZZZ (list)
cf = customFieldManager.getCustomFieldObjects(issue).find { == 'ZZZZZ'}
newissue.setCustomFieldValue(cf, issue.getCustomFieldValue(cf))
//YYYYYY (date) another way to obtain the custom field
cf = customFieldManager.getCustomFieldObject("customfield_NNNNN");
newissue.setCustomFieldValue(cf, issue.getCustomFieldValue(cf))
//XXXXXX (text, numeric, ...)
cf = customFieldManager.getCustomFieldObjects(issue).find { == 'XXXXX'}
newissue.setCustomFieldValue(cf, issue.getCustomFieldValue(cf))

def params = ["issue":newissue]
def subTask = issueMgr.createIssue(currentUserObj, params)

def linkMgr = ComponentManager.getInstance().getIssueLinkManager()
linkMgr.createIssueLink (,, Long.parseLong("ZZZZZ"),Long.valueOf(1), currentUserObj) //ZZZZZ is the id of the type of link



If using post function Clones an issue and links , how to get new clone issue id and original issue id?

I did try issue.getid() , but no luck.

The object for new cloned issue will be sourceIssue

I hope you are using getId() and not getid() .

Try to use as much logging as possible it will be helpful

@Mizan Ali Sayed

After working around, I got code below, but looks like getId() is still null. code as below:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions
MutableIssue issue = issue
def id=issue.getId()
def pid = sourceIssue.getId()
def creatorid = sourceIssue.getCreatorId()
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find { == 'ECUlist'}
issue.setCustomFieldValue(cf, sourceIssue.getCustomFieldValue(cf))
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
//used for debug
log.debug "I will transit the subtask " + issue.key
log.debug "I will transit the subtask " +
log.debug "I will transit the subtask " + issue.getId()
//issue.summary = 'NEW Cloned Issue: ' + sourceIssue.summary
//issue.summary = "NEW Cloned Issue: " + "line 0 summary " + "sourceIssue.summary " + sourceIssue.summary

doAfterCreate = {

def cwdUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
log.debug "I will transit the subtask " + issue.key
issue.summary = "NEW Cloned Issue: " + "line 1 summary " + "sourceIssue.summary " + sourceIssue.summary


def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.getIssueManager()

doAfterCreate = {
def issueToLinkTo = issueManager.getIssueByCurrentKey(sourceIssue.getId().toString())
def duplicateLinkTypeName = "Duplicate"

issue.summary = "NEW Cloned Issue: " + "line 1 summary " + "sourceIssue.summary " + sourceIssue.summary

// issue.summary = "NEW Cloned Issue: " + "line 2 summary" + "sourceIssue.summary " + sourceIssue.summary
// issue.summary = "NEW Cloned Issue: " + "line 3 summary" + "sourceIssue.summary " + sourceIssue.summary + "sourceIssue id: " + sourceIssue.getId()
// issue.summary = "NEW Cloned Issue: " + "line 4 summary" + "sourceIssue.summary " + sourceIssue.summary + "sourceIssue id: " + sourceIssue.getId() +

def duplicateLinkType = issueLinkTypeManager.getIssueLinkTypesByName(duplicateLinkTypeName)

if (!duplicateLinkType) {
log.warn ("Issue link type with name: ${duplicateLinkTypeName} does not exist")
else {
issue.summary = 'NEW Cloned Issue: ' + sourceIssue.summary + ' ' + + ' ' + sourceIssue.getId().toString()+ ' ' + issue.getId().toString()+ ' ' +
// issueLinkManager.createIssueLink(issue.getId(),, duplicateLinkType[0].id, 1, currentUser)
issueLinkManager.createIssueLink(issue.getId(), sourceIssue.getId(), new Long(12000), null, authenticationContext.getLoggedInUser())


Which post function are you using ? 

Custom script or Clone issue ? 


This is not correct 

def issueToLinkTo = issueManager.getIssueByCurrentKey(sourceIssue.getId().toString())

issue id eg: 10001 , issue key eg: EX-109 .

@Mizan Ali Sayed

ScriptRunner workflow function - Clones an issue and links (condition & additional actions apply).

@Mizan Ali Sayed

Is there anyway we can setup a webex meeting?

Sorry, that wont be possible.

Why you need any scripting if you are using clone issue function ?

Did you even try this and checked how it works ?

All you need to do is have multiple post functions for cloning the issue and linking. Each post function will have a condition which will check the drop down list value if it passes it will execute else return false. 

@Mizan Ali Sayed

Thanks for point out,

After I change togetKey(), still have same issue.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


232 views 0 6
Read article

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