Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

link issues using script

Georges Moubarak
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.
July 6, 2016

Hi,

I am linking issues by using the blow code

issueLinkManager.createIssueLink(issue.getId(),issueObject.getId(),10003,1,issue.getAssignee());

This line of code links the issues and makes the assignee as the action maker. 

I need to set a specific user to be the action maker of the linking. How to update the above code to do so?

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
adammarkham
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.
July 7, 2016

You should be able to get the user like in the following snippet and replace "issue.getAssignee()" with "user" like on the last line:

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.userManager
def user = userManager.getUserByKey("admin")
// get by username below, above gets user by key (incase user is renamed)
//userManager.getUserByName("admin")

issueLinkManager.createIssueLink(issue.getId(), issueObject.getId(), 10003, 1, user);
Georges Moubarak
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.
July 7, 2016

Dear @Adam Markham [Adaptavist],

I tried your script but got the below error:

[scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: CR-9423, actionId: 1881, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.link.DefaultIssueLinkManager.createIssueLink() is applicable for argument types: (java.lang.Long, java.lang.Long, java.lang.Integer, java.lang.Integer, com.atlassian.jira.user.DelegatingApplicationUser) values: [88828, 108907, 10003, 1, jiraadmin(jiraadmin)]
adammarkham
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.
July 7, 2016

Your probably on JIRA 6. They changed User to ApplicationUser for JIRA 7. For 6 Please use: 

import com.atlassian.jira.component.ComponentAccessor
 
def userManager = ComponentAccessor.userManager
def user = userManager.getUserByKey("admin").directoryUser
// get by username below, above gets user by key (incase user is renamed)
//userManager.getUserByName("admin")
 
issueLinkManager.createIssueLink(issue.getId(), issueObject.getId(), 10003, 1, user);
Like Cassio likes this
Georges Moubarak
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.
July 7, 2016

Thanks @Adam Markham [Adaptavist],

It works fine!!!

Teja April 3, 2019

Hi @Adam Markham

issueLinkManager.createIssueLink(issue.getId(), issueObject.getId(), 10003, 1, user);

How to create inward link name using this createIssueLink? 

TAGS
AUG Leaders

Atlassian Community Events