Forums

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

Can a postfunction create a task and then also subtasks to the task using scriptrunner

Gregory Bowe
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 18, 2021

I would like to create an Issue in a workflow postfunction, very simple.  However, I also want to create sub-tasks in the created Issue. Can that be done with scriptrunner or some other tool?

 

2 answers

2 accepted

0 votes
Answer accepted
Payne
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.
August 18, 2021

Create your subtask(s) like any other issue (setting the necessary attributes, such as issue type [a type that is a subtask]), and then use the following bit of coding to link it to its parent. I'm not sure that both are necessary; I used them both when I scripted subtask creation a while back.

While setting the subtask attributes, use the setParentObject() or setParentId() method: https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/MutableIssue.html#setParentObject-com.atlassian.jira.issue.Issue-

After creating the subtask issue, link it to its parent with the createSubTaskIssueLink() method in the SubTaskManger class: https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/config/SubTaskManager.html

0 votes
Answer accepted
Nic Brough -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.
August 18, 2021

Yes, there are a number of tools you can add to Jira that can do this sort of thing.

A starter for Scriptrunner is probably https://library.adaptavist.com/entity/create-sub-tasks-when-an-issue-is-created - I usually steal that and extend it.  

If you do decide to do this with SR, then remember that you'll need to create the main issue first, then add sub-tasks to it later.  The parent issue needs to exist for the sub-tasks to be attached.

I mean, if you have a script that does this:

  • Work out what issue to create and add it to a list
  • Work out a list of sub-tasks and add them to the list
  • Iterate through list creating them all

It is likely to fail.  Your script should be more:

  • Work out what issue to create and create it
  • Work out a list of sub-tasks and add them to the list to create in the next section, or just create them as you work each one out

Suggest an answer

Log in or Sign up to answer