how to use jira automation to create multiple issues based on a number field

yousefq August 7, 2023

Hello,

I have an issue that contains a numeric field called "quantity". I'd like to be able to create a number of new issues based on the quantity field. For example, if the quantity field has 10, I'd like to create 10 new issues. If it has 100, I'd like to create 100 new issues.

What is the best way of implementing this?

Thank you,

Yousef

5 answers

1 accepted

2 votes
Answer accepted
Bill Sheboy
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 7, 2023

Hi @yousefq -- Welcome to the Atlassian Community!

One way to do this with one rule is to use the rightPad() function to create a text string of the length of your 2 x count - 1 (e.g. For 5 items "z,z,z,z,z"), split the string on the delimiter (i.e., a comma), and use that to drive an advanced branch to create the issues.

If you want to use the counter number as part of the issue creation, that will take some extra steps using the {{index}} of the split values.

Here is a post I wrote on that last year: first part for the basic rule, and an enhancement to use counters in the branch.

Kind regards,
Bill

yousefq August 16, 2023

Hi bill.

Thanks! This worked exactly how I wanted it to.

Like Bill Sheboy likes this
yousefq August 27, 2023

Hi Bill,

hope you are doing well. 

can you kindly support me in implementing the enhancement on the solution. 

I’ve been trying to get the index as you mentioned in your post but I’m not able to get it right

 

where should I add this line? 

{{#=}}{{index}}+1{{/}}{{^last}},{{/}}{{/}}


and how do I get the index in the summary field of the created issues?

I tried adding this to the summary field:

{{#=}}{{index}}+1{{/}}{{^last}}{{/}}

but the index was always 1 (did not change)

Bill Sheboy
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 27, 2023

Hi @yousefq 

If you refer back to the two earlier posts noted, that part of the smart value expression is nested inside of an iterator, and is used to set a counter (or other field).

Kind regards,
Bill

yousefq August 28, 2023

Hi @Bill Sheboy

 

I added the expression in the iterator (as shown in the screenshot below)

 

Screenshot 2023-08-28 at 11.57.10 PM.png

 

Then added the same expression in a custom field "index" to get the index (as shown in the screenshot below). However i got an error

 

Screenshot 2023-08-28 at 11.57.36 PM.png

 

I also tried removing this part:   {{^last}},{{/}}{{/}}

 

The error was gone, however, when I tested the automation:

* 2 issues were created (correctly)

* The index field got updated to a value of 1 for both issues (did not increment)

 

I really appreciate your help 

 

Kind regards,

Yousef

Bill Sheboy
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 28, 2023

That second image's version will not work without the iterator as it provides the list...leading to {{index}} working.  The original example from the post will work...

  • Please copy the smart value expression you are using to create varLoopValues and post that complete expression as text. 
  • Then please show the smart value expression used in the Advanced Branch.

I suspect one (or both) of these is incorrect for your specific field with which to count.

1 vote
Markus W_ BENES
Contributor
August 8, 2023

@yousefq a third way would be to realize that via ScriptRunner; get the quantity value and make a for loop in that the tickets be created; a first example:

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue

// Get the current issue

def toChangeIssue = "IT-12345" // ticket Key or issue.getKey() to use in automation
def customFieldId = "Customfield_123456" // field that contains number to loop

// search Issue by Key
IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue issue = im.getIssueObject(toChangeIssue)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def Object cField

cField = customFieldManager.getCustomFieldObject(customFieldId.toLowerCase());        

def loop = issue.getCustomFieldValue(cField)


for(int i = 0;i<loop;i++) {

Issues.create('IT', 'Customer Request') { // Issues.create(Project Key, Issue Type)

    setSummary('my Summary')
    setDescription('my description')

    // and custom field values
    // setCustomFieldValue('Name of custom field', 'more text')

}

}
1 vote
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 7, 2023

Hi @yousefq

Welcome to Atlassian Community!

Have a look at this article, How to create dynamic looping in Automation for Jira, it describe how you can do this using two automation rules and using dynamic values. 

0 votes
Oussama Brik February 16, 2024

this is my solution for the same situation I had.

I combined scriptrunner and automation so I could create a sub-task if a field was modified:

// Retrieving the custom field 'ports quantity'
def nombre = issue.getCustomFieldValue('ports quantity')

// Retrieving the issue by its key
def Issue = Issues.getByKey(issue.key)

// Converting the field to an integer to ensure the same INT type
def nombreEntier = nombre.toInteger()

// Declaring the loop variable
int loop

// All definitions and conversions are to ensure the use of the same INT type

// To prevent my users from creating more than 5 sub-tasks
if (nombreEntier > 5) {
loop = 5
} else {
loop = nombreEntier
}

// Loop to create sub-tasks based on the number of ports
for (int i = 0; i < loop; i++) {
Issue.createSubTask('Sub-Task') {
setSummary(Issue.summary + ' - port-' + (i+1)) // You can add whatever text you want
}
}

 2024-02-16 18_03_44-Automation - Jira et 30 pages de plus - Travail – Microsoft​ Edge.png2024-02-16 18_04_04-Automation - Jira et 30 pages de plus - Travail – Microsoft​ Edge.png2024-02-16 18_08_28-Automation - Jira et 30 pages de plus - Travail – Microsoft​ Edge.png

0 votes
Thibaut Subra _Elements_
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 9, 2023

Hi @yousefq 

We have a way to do this with our application Copy & Sync where you can determine how many issues you will create based on a custom field (number type).

Here is an example of how to do it based on the Components field but it's the same logic based on a number field.

It could look like something like this, where the primary field "Issues to create" will determine how many issues will be created based on the source issue.

 

Capture d’écran 2023-08-10 à 08.45.11.png

The only limitation regarding your need, is that it's limited to 25 issues at a time for now.

Feel free to give it a try (it's free under 10 users and we have a 30-Day trial policy) and don't hesitate if you have any question!

Regards

Thibaut

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events