Automatic creation of sub-task for linked issues

Vik Kay December 22, 2015

Hi there,

I have a main issue (issue-1) in project A, and some related to it issues (issue-2,issue-3,...) in project B.

They are linked - from issue-1 I can see link(s) "realize in" to issue-2,issue-3,...

On some action with issue-1 (transition? sub-task creation?) I need to create sub-task for issue-2 (in project B), and this sub-task should also have a link to issue-1.

How it can be done with JIRA?

I have ScriptRunner 3.0.5, but could you please point me to example of code?

And another important thing - this newly created sub-task should have some input from user during creation (at least Summary and Description). How to achieve this during transition?

2 answers

0 votes
Thanos Batagiannis [Adaptavist]
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.
December 22, 2015

Hi Vik,

One way to do this is using script runner for JIRA plugin. If you are familiar with groovy language then you can write a very simple script or use one of the built in scripts (create a sub task) during a workflow transmission. You can also have a look at the documentation.  

Vik Kay December 22, 2015

Yes, I have ScriptRunner 3.0.5, but could you please point me to example of code? And another important thing - this newly created sub-task should have some input from user during creation (at least Summary and Description). How to achieve this during transition?

Chander Inguva
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.
December 22, 2015
Thanos Batagiannis [Adaptavist]
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.
December 22, 2015

Vik, There is a script which will give yo a hint (the script is not tested) of how your custom script should be. @Chander Inguva FYI depending on which version of JIRA you use the above link may contain outdated code. import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue Issue currentIssue = event.issue def user = ComponentAccessor.getJiraAuthenticationContext().getUser() def issueFactory = ComponentAccessor.getIssueFactory() def subTaskManager = ComponentAccessor.getSubTaskManager() def constantManager = ComponentAccessor.getConstantsManager() def issueManager = ComponentAccessor.getIssueManager() def issueLinkManager = ComponentAccessor.getIssueLinkManager() // get all the outward links from that issue def linkedIssuesList = issueLinkManager.getOutwardLinks(currentIssue.id) def realiseInIssues = [] // add in a list all the issues that re linked with a realize in link type for (issueLink in linkedIssuesList) if (issueLink.getIssueLinkType().name == 'realize in') realiseInIssues.push(issueLink.destinationObject) // for every link to currentIssue issue, create sub-tasks for (Issue linkedIssue in realiseInIssues) { MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setSummary("Add a summary") newSubTask.setParentObject(linkedIssue) newSubTask.setProjectObject(linkedIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{ it.getName() == "Sub-task" }.id) newSubTask.setDescription("Add a description") // in order to create a link between two issues use the // issueLinkManager.createIssueLink(Long sourceIssueId, Long destinationIssueId, Long issueLinkTypeId, // Long sequence, com.atlassian.crowd.embedded.api.User remoteUser) // https://docs.atlassian.com/jira/6.4.1/com/atlassian/jira/issue/link/IssueLinkManager.html Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user.directoryUser, newIssueParams) subTaskManager.createSubTaskIssueLink(linkedIssue, newSubTask, user.directoryUser) log.info "Issue with summary ${newSubTask.summary} created" } Kind regards Thanos

0 votes
Chander Inguva
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.
December 22, 2015

Hi Vik Kay,

                 If you have script runner add-on installed on your instance, you can create a post function on transition.

This is one of the possible solution.

What is you JIRA Version ? As, last free version of script runner is available only for JIRA 6.4.12 and script runner version is 3.1.4

https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner/versions

Regards

Chander Inguva

Vik Kay December 22, 2015

Yes, I have ScriptRunner 3.0.5, but could you please point me to example of code? And another important thing - this newly created sub-task should have some input from user during creation (at least Summary and Description). How to achieve this during transition?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events