createIssueLink do not work

Hi all

jira 7.8.0 and script runner 5.3.16

I just recently started learning java and groovy.

This code is kind of a mess, however he in it all works except createIssueLink in doAfterCreate closure.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.ComponentManager

// edit the JQL to return the issues you want to clone

def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()

MutableIssue curIssue = issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def tempCF = customFieldManager.getCustomFieldObjectByName("Target clone project")
def checkbox_field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Target clone project")
def List<Option> getOptions(Issue issue, CustomField customField, List<String> optionList) {
    def config = customField.getRelevantConfig(issue)
    def options = ComponentAccessor.getOptionsManager().getOptions(config)
    def optionsToSelect = options.findAll { it.value in optionList }
     def listOfValues = curIssue.getCustomFieldValue(tempCF)
    def tempVAL = curIssue.getCustomFieldValue(tempCF);

def myFieldList2 = [];
for (myFieldName2 in listOfValues) {
    String strMFN = myFieldName2

for (myFieldName in listOfValues )

// clone the current issue
def newIssue = issueFactory.cloneIssue(issue)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
//def issueManager = ComponentAccessor.getIssueManager()

doAfterCreate = {
    def issueToLinkTo = issueManager.getIssueByCurrentKey(newIssue.getKey())
        issueLinkManager.createIssueLink(curIssue.getId(), newIssue.getId(), 10001, 1, user)

String result = myFieldName

// set the project and any field you want to have a different value
def projectTo = ComponentAccessor.getProjectManager().getProjectByCurrentKey(result)
newIssue.setCustomFieldValue(checkbox_field, getOptions(issue, checkbox_field, myFieldList2))

Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams) "Issue ${newIssue?.key} cloned to project ${projectTo.key}"

in line

issueLinkManager.createIssueLink(curIssue.getId(), newIssue.getId(), 10001, 1, user)

Cannot find matching method{java.lang.Long java.lang,Long, int, int, com.atlassian,jira.user,ApplicationUser),
Please check if the declared type is right and if the method exists.

in the documentation:

Exist class IssueLinkManager and method createIssueLink.

Prompt in what there can be a problem and how to correct?

2 answers


Can you try modifiying the code like below and try?

issueLinkManager.createIssueLink(curIssue.getId() as Long, newIssue.getId() as Long, 10001 as Long, 1 as Long, user)


Thank! In your answer there is progress for me - static type checking stopped finding errors in line issueLinkManager.createIssueLink...

But the creation of linkages between the issue still doesn't work.

Static type cheking still say "The variable [doAfterCreate] is undeclared" - as far as I understand this is not an trouble?

Post-function works without errors, but the link is not created


You have written doAfterCreate in the code but havent declared it anywhere. You have to define it so that this error goes off. Also do you really require that "doAfterCreate"?

def doAfterCreate

Also do you really require that "doAfterCreate"?


I would like to explain the ultimate goal:
In a loop I clone issue(curIssue) and using "doAfterCreate" I expect curIssue to be linked with newIssue(cloned issue).


Then you can just add 'def' before it, so that it is defined.

- Praveen

I did this:

def doAfterCreate = {
issueLinkManager.createIssueLink(curIssue.getId() as Long, newIssue.getId() as Long, 10001 as Long, 1 as Long, user)


And the above code does not work.

I don't understand . This example:

Support scriptrunner use doAfterCreate without declare.

It seemed to me that doAfterCreate is a system variable.

Yes, you are correct. It is a system variable and doesnt have to be declared (sorry for the confusion caused).

@Thanos Batagiannis [Adaptavists] Requesting your help here. 

You can find the documentation here (under After create options),

It seems since version 5.3.0 there is a bug in the documentation:

doAfterCreate documentation for 5.2.2:

doAfterCreate documentation for 5.3.16:

@Praveen while waiting for a response from support for scriptrunner. Could you check the following statement?

The above script is placed in post-function which is bound to transition "create".
Do I understand correctly that at the moment of creation issue 

on transition "create" curIssue.getId() exist

however on transition "create" newIssue.getId() not exist

This is the right statement?

I will explain what my question is related to: 

I saw that on transition "create" curIssue.getId() NOT EXIST


curIssue.getId() should work because the current issue already exists.


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,701 views 3 11
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