Forums

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

Need help with Groovy Script for linking two subtasks together

Michael
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.
March 20, 2020

Hello,

 

I'm trying to mark two subtasks under the same parent ticket as "related" within a post function using a normal (non-script runner) groovy script.

 

So far, with the help of the community, I've been able to do this "manually" with the code below:

import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.JiraAuthenticationContext

def issue1 = ComponentAccessor.issueManager.getIssueByCurrentKey("ticket-113")
def issue2 = ComponentAccessor.issueManager.getIssueByCurrentKey("ticket-111")

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
def user = authContext.getLoggedInUser();
issueLinkManager.createIssueLink(issue1.getId(), issue2.getId(), Long.parseLong("10303"),Long.valueOf(1), user);

However, I need this to happen automatically where:

a) "issue1" calls the issue ID of the issue the post function is being performed within.

b) "issue2" finds the most recent issue ID of any subtasks underneath the parent ticket which have the issue type ID of "10107".

After many hours of looking over a lot of different forums and asking tons of different people I believe the following code plays a role in finding the above subtask needed, but I need help with finalizing the above code to answer for A & B. Can someone help me resolve this issue?

subtask code:

Issue parent = issue.getParentObject()


Collection<Issue> subtasks = parent.getSubTaskObjects()

0 answers

Suggest an answer

Log in or Sign up to answer