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
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
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy
I added the expression in the iterator (as shown in the screenshot below)
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
I suspect one (or both) of these is incorrect for your specific field with which to count.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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')
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.