Automatic creation of sub-task for linked issues

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

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

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?

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.  

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?

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

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

265 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot