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()