Hi everyone,
I have a subtask being created (subtask A) via the parent ticket that relates to another subtask which is always previously created. (Subtask B)
I'd like to use a Groovy Script through the Workflow Magic Box Jira plugin to link subtasks A and B as being "related".
Can anyone help me create a Groovy script for this?
Thanks,
Michael
Hi again @Payne or anyone else who might be able to help,
Can you think of any way to have the above code "auto retrieve":
a) Issue ID that the post function is being created
b) The issue ID of the most recent specifically defined subtask / subtask ID within the same parent issue?
The main reason for creating this type of link, is that we want both of the issues to be subtasks under the same parent, but we want to link them together so that people know they are related to each other.
I use the following code that you can hopefully massage and put to use.
jiraAdminUser is an ApplicationUser object representing the user that is performing the action.
issue and linkedIssue are Issue objects representing the 2 issues that we wish to link.
linkTypeApprove is the ID (e.g. 10200) of the link type.
import com.atlassian.jira.bc.issue.IssueService
IssueService.IssueResult iResult = issueService.create(jiraAdminUser, issue);
issueLinkManager.createIssueLink(linkedIssue.getId(),iResult.getIssue().getId(),linkTypeApprove,(Long)1,jiraAdminUser)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Payne thanks for the quick reply.
This is my first time messing with groovy, so sorry if I get this wrong but am I understanding correctly that I only need to add the issue link ID within the ",(Long)1" section?
If so, how does this script know which subtask I'd like to link under the parent ticket? I was expecting I'd have to call out the issue type name / ID so that it knows how to link the current issue I'm deploying this script within to the one called out within the script.
Thanks,
~Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Right, that's what issue and linkedIssue are - those are the two issues being linked. (Long)1 is the sequence; see the method definition at https://docs.atlassian.com/software/jira/docs/api/7.0.4/com/atlassian/jira/issue/link/IssueLinkManager.html#createIssueLink-java.lang.Long-java.lang.Long-java.lang.Long-java.lang.Long-com.atlassian.jira.user.ApplicationUser-
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Payne
Thanks for the continued back and forth. After look at the documentation a lot more and browsing more community posts / forums, I've come up with the following script, but I still can't get it to work:
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.crowd.embedded.api.User
Issue issue = issue;
def parentIssue = issue.getParentObject();
issueManager = ComponentManager.getInstance().getIssueManager()
subTaskManager = ComponentManager.getInstance().getSubTaskManager();
subTasks = subTaskManager.getSubTaskObjects(parentIssue)
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
User user = authContext.getLoggedInUser();
String issueKey = issue.key;
subTasks.each() {
String issueTypeId = it.issueTypeObject.id
if (issueTypeId == "10107") {
issueLinkManager.createIssueLink(issue.getId(), it.getId(), Long.parseLong("10303"),Long.valueOf(1), user);
issueManager.updateIssue(user, it, EventDispatchOption.ISSUE_UPDATED, false)
}
}
The issueTypeId 10107 is the issue type ID of the subtask I want the script to find.
The Long.parseLong("10303") is the issue link ID of the issue link I want to create between the subtask I'm adding this script to, and the subtask I want linked.
If you could point me in the right direction I'd appreciate it.
Thanks again,
~mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Mike,
I'd put some logging in to figure out where breakdown is occurring. I stripped your script down to the bare minimum to simply create a link between 2 issues and confirm that it runs as expected in the ScriptRunner console:
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.JiraAuthenticationContext
def issue1 = ComponentAccessor.issueManager.getIssueByCurrentKey("BR-1")
def issue2 = ComponentAccessor.issueManager.getIssueByCurrentKey("BR-2")
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
def user = authContext.getLoggedInUser();
issueLinkManager.createIssueLink(issue1.getId(), issue2.getId(), Long.parseLong("10001"),Long.valueOf(1), user);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Payne ,
Thanks again for the continued help. I input the above code and massaged it to work with our instance, and it worked:
Is it normal to get "no return value" for linking issues when testing groovy scripts?
Also, I now need to figure out how to "auto" grab the required issue types... I'm thinking the newly created subtask shouldn't be that hard, but I need to somehow search all subtasks within the parent ticket, and grab the latest ticket of a specific issue type.
@Paynecan you think of anyway that I can do the above?
Thanks again,
~Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.