Forums

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

Generate issue links in Jira with scriptrunner

Mouna Hammoudi
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 18, 2023

I am trying to generate some issue links in jira, here is my code. This code is executed as a Jira automation rule after clicking on a button.  The problem is that I receive the following error message. They say that the issuelinktype is wrong, anyone knows how to figure out which issue link type I need? 

 

Capture.PNG

package SuperFeature

import com.atlassian.jira.bc.project.component.ProjectComponent

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.Issue

import org.apache.log4j.Logger

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.util.ImportUtils

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.issue.index.IssueIndexManager

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

import com.atlassian.jira.issue.index.IssueIndexingService

def log = Logger.getLogger('atlassian-jira.log')

log.warn("MOUNA: ")

log.warn("MOUNA COMPONENT NUMBERS : "+ issue.getComponents().size())

List<String> componentList = new ArrayList<String>()

def authenticationContext = ComponentAccessor.jiraAuthenticationContext

if (issue.getComponents().size()==0){

    log.warn("MOUNA CAMELIA COMPONENTS")

    issue.update {

    String text= "Issue does not have any components\n"

    setCustomFieldValue('Execution Summary', text)

    }

}else if(issue.getFixVersions().size()==0){

            log.warn("MOUNA CAMELIA VERSIONS")

            issue.update {

                String text= "Issue does not have any fix versions\n"

                setCustomFieldValue('Execution Summary', text)

                }

   

}

else{

            log.warn("MOUNA CAMELIA ELSE")

        int componentSize=issue.getComponents().size()

        for(ProjectComponent component : issue.getComponents()) {

                componentList.add(component.getName())

        }

        issue.update {

            String text= "The super feature "+issue+" will be split into "+componentSize+

            " features, one for each component:\n"

            for(String component: componentList){

                text = text +"-"+ component+"\n";

            }

            setCustomFieldValue('Execution Summary', text)

}

// Issue issue

def issueManager = ComponentAccessor.issueManager

def issueFactory = ComponentAccessor.issueFactory

def subTaskManager = ComponentAccessor.subTaskManager

def issueLinkManager = ComponentAccessor.issueLinkManager

def userManager = ComponentAccessor.userManager

// Defining subtask

def newIssue = issueFactory.getIssue()

newIssue.setParentId(issue.getId())

log.warn("MOUNA CAMELIA issue.getId()"+ issue.getId())

def Long issueLinkType = new Long (19)

def Long sequence = new Long (1)

newIssue.setProjectObject(issue.getProjectObject())

newIssue.setSummary("MOUNA CAMELIA")

newIssue.setAssignee(userManager.getUserByName("mouh"))

newIssue.setDescription(issue.getDescription())

                for(String component: componentList){

                    def subTask = issueManager.createIssueObject(authenticationContext.getLoggedInUser(), newIssue)

                    subTaskManager.createSubTaskIssueLink(issue, subTask, authenticationContext.getLoggedInUser())

                    log.warn("MOUNA CAMELIA Component "+ component)                

                   issueLinkManager.createIssueLink(issue.getId(), newIssue.getId(), issueLinkType, sequence, authenticationContext.getLoggedInUser())

        }

}

1 answer

0 votes
Trudy Claspill
Community Champion
September 18, 2023

Have you confirmed that you do in fact have a link type in your system that has the ID 10001?

Mouna Hammoudi
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 18, 2023

how can I know??

Trudy Claspill
Community Champion
September 18, 2023

A Jira Administrator can navigate to Jira Settings > Issues > Issue Linking to find the ID for each link type.

Clicking on the Edit option for a link type will show the link type ID in the URL:

https://<baseURL>/secure/admin/EditLinkType!default.jspa?id=10000

Mouna Hammoudi
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 19, 2023

The right ID is 19 and I have used it and it is till not working. 

 

Capture.PNG

Trudy Claspill
Community Champion
September 19, 2023

That is not the issue linking screen. Notice that the URL you see at the bottom of the screen does not match what I specified.

The URL for the Issue Linking screen that shows all the link types is

https://<your base URL>/secure/admin/ViewLinkTypes!default.jspa

It will look similar to the below screen. You need to click the Edit option next to the link type you are trying to create in your code.

Screenshot 2023-09-19 at 7.42.34 AM.png

Suggest an answer

Log in or Sign up to answer