JMWE - Create issue and its subtasks in another project

Ahmad Sidawi May 18, 2023

Hi, 

 

I'm looking to use the Create Issue post function to create an issue and all its subtasks in another project. I assumed this should split between two post functions but i'm struggling to iterate through the current issue's subtasks to get all their data and create them in the other project.

 


Screenshot 2023-05-18 121137.png

2 answers

1 accepted

1 vote
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 18, 2023

Hi @Ahmad Sidawi 

first of all, the two Create Issue(s) post-function must be in a Sequence of Post functions post function, unless you're using them in an Action (Shared, Scheduled or Event-based) to ensure the post-functions run one after the other (Jira doesn't guarantee that third-party post functions on issue transitions run sequentially).

Then, in the second post-function that clones the sub-tasks :

  1. for the Issue Type, select "Calculated" and use {{it.fields.issuetype.id}} as the Nunjucks template
  2. For Parent Issue, select "Another Issue" and use this template: {{context.newIssueKey}}
  3. Choose the desired "Copy fields to new issue(s)" option
  4. For the Summary field, use this as the value: {{ it.fields.summary }}
  5. Check the "Create multiple issues" option and use this as the iterator: {{issue | subtasks( "*all" ) | dump(2)}}
  6. Check the "Iterator returns JSON" option

image.png

Ahmad Sidawi May 19, 2023

Worked! I replaced the ContextIssue for Parent with a SearchIssues as the ContextIssue didn't work. One more thing, is it possible to auto link the generated subtasks to the original subtask? So if the Parent ticket is 'blocked by' or 'addressed by', can the subtasks have that link to each other rather than the Parent? (this could be done through a Jira automation or a separate action but just wondering if possible through the CreateIssue action)

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 19, 2023

You should be able to achieve this by adding the "Linked Issues" field to the "Set specific fields of new issue(s)" section, like this:

image.png

Note that you'll need to update the link type name (careful, it's the link type name as it appears on the "Issue Linking" Jira admin page, not the link type direction). You might also need to replace "outwardIssue" with "inwardIssue" depending on the direction of the link to create between the two subtasks.

Like Ahmad Sidawi likes this
Ahmad Sidawi May 31, 2023

@David Fischer 

Last question, when iterating through the subtasks to create, can I filter out subtasks in a statusCategory of done? I've tried using filter but to noScreenshot 2023-05-31 203849.png avail yet

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2023

Hi @Ahmad Sidawi ,

you can use this as the iterator:

{{ issue | subtasks("*all") | filter(["fields.status.statusCategory.name","Done"], true) | dump(2) }}
Like Ahmad Sidawi likes this
Ahmad Sidawi June 2, 2023

If i wanted to use Status instead and filter out several states would it be this? 

 

{{ issue | subtasks("*all") | filter(["fields.status.name",("To Do", "In Progress")], true) | dump(2) }}

 

It worked for single states but multiple didn't. Was looking for an example here:

https://innovalog.atlassian.net/wiki/spaces/JMWEC/pages/138405679/Custom+Nunjucks+filters#filter

but they reference a single value.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 2, 2023

Unfortunately, you cannot filter out multiple values in one call to the "filter" filter. You need to use multiple calls to eliminate each status one after the other:

{{ issue | subtasks("*all") | filter(["fields.status.name","To Do"], true) |  filter(["fields.status.name","In Progress")], true) | dump(2) }}
1 vote
Evn Tomeny _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 18, 2023

Hi @Ahmad Sidawi

Let's start by setting our Iterator, then add the fields we want to grab. To begin, set this as your iterator, and test it against an issue that has Subtasks:

{{issue.fields.subtasks | dump(2) }}

You should see a JSON output of all of the subtasks of the issue you test against. Make sure you check the "Iterator returns JSON" box. Now we can set Summary to:

{{ it.fields.summary }} 

and Priority to:

{{ it.fields.priority.name }}

Unfortunately, this object only returns a subset of available fields for an issue, so it own't work for every field you may want to copy. You may be able to use the "subtasks" filter to build an array of each of the fields you want, but I'm not sure.

Cheers,
Evn

Suggest an answer

Log in or Sign up to answer