Automation Transition : Create Multiple Sub Tasks Dynamically Based on Field Value
Asked by Asheesh:

Hi,

Create Multiple Sub Tasks, based on a field value, for example if UT-IssueCount is 3 , then we should create 3 Sub Tasks.

All during transitions from one stage to another.

Though, rule is working, but only once, no errors etc.

Have a look at the screen shot attached, for information.

![Screenshot 2024-09-22 at 7.31.46?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/348575i3B24EBF8B37B676A/image-size/large?v=v2&px=999 "Screenshot 2024-09-22 at 7.31.46?PM.png")![Screenshot 2024-09-22 at 7.32.05?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/348576i2091898FC16B50ED/image-size/large?v=v2&px=999 "Screenshot 2024-09-22 at 7.32.05?PM.png")


Answers:
author: Bill Sheboy
body: Hi [@Asheesh](/t5/user/viewprofilepage/user-id/5493246)

What is the type of your field, UT-IssueCount? Is it a numeric field?

Please show an image of your advanced branch to provide context.

Until we see those...

There is no built-in branch type to iterate over a numeric value. Instead you may try a couple of possible workarounds:

* Use a text string to replicate the issue count (e.g., with the rightPad function), split on the values, and then iterate on each one. Please see this post where I describe the technique: <https://community.atlassian.com/t5/Jira-questions/how-to-use-jira-automation-to-create-multiple-issues-based-on-a/qaq-p/2443240>
* Using the Send Web Request action and an Incoming Webhook trigger, use a rule to recursively trigger itself for the count. This approach seems excessive for your scenario, but if you want to try it here is how-to article: <https://community.atlassian.com/t5/Jira-Service-Management-articles/How-to-create-dynamic-looping-in-Automation-for-Jira/ba-p/2293077>

Please note the first technique is limited to 100 items as that is the branching limit. The second technique ***might***be limited to 10 items due to the service limit for recursive rules.

Kind regards,  
Bill

comments: author: Asheesh
body: Thanks a lot Bill, the data type is indeed numeric.

Let me try your suggestive rightPad function.

Meanwhile have a look at the attached screen shot.

Regards

Asheesh


author: Asheesh
body: Screen Shot Attached


author: Asheesh
body: Screen Shot


author: Bill Sheboy
body: Your screen images did not post, but they may not be needed. As your field is numeric please try the rightPad() technique and let me know how that helps. Thanks!


author: Asheesh
body: Thanks Bill,

Planning to remove this one \& replace it another one.

Could you please advise the data type/field type to be used.

Regards

Asheesh


author: Bill Sheboy
body: Please clarify what you mean by remove / replace.

The number field will work with the rightPad() technique to branch for a number of times: <https://community.atlassian.com/t5/Automation-articles/Branching-over-smart-values-in-Jira-Automation/ba-p/1741935#M531>


author: Asheesh
body: Bill,

Looks I am confused with rightPad() function, could you please write syntax/use of rightPad() with Number data type.

{{issue.UT-IssueCount}} ........Numeric Variable

Regards

Asheesh


author: Bill Sheboy
body: Your custom number field would substitute in the example I provided. And so the value of the varLoopValues variable would be:

```
{{varLoopValues.rightPad(varLoopValues.length.plus(issue."UT-IssueCount"), "X").remove("NULL").replaceAll("X","X,").substringBeforeLast(",")}}
```

Assuming that is the correct smart value for your field.

If that does not help, please pause to review the other post I linked to and check your rule steps. Then post an image of your complete rule and the audit log details for context.


author: Asheesh
body: Thanks Bill. Will try.


author: Asheesh
body: Hello Bill,

Getting errors, attached screen shots,

@https://community.atlassian.com/t5/Automation-articles/Branching-over-smart-values-in-Jira-Automation/ba-p/1741935/page/2#U2818662

Thanks

Asheesh<https://community.atlassian.com/t5/Automation-articles/Branching-over-smart-values-in-Jira-Automation/ba-p/1741935/page/2#U2818662>


author: Bill Sheboy
body: [@Asheesh](/t5/user/viewprofilepage/user-id/5493246) -- I responded on the other thread as you are missing several steps to use the rule technique I described.

Kind regards,  
Bill


author: Asheesh
body: Thanks Bill


author: Asheesh
body: Bill,

Updated workflow, have a look at the diagram, only 1 sub issue is created


author: Asheesh
body: ![Screenshot 2024-09-24 at 3.22.25?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/348932i5E45DB182DBAEF4D/image-size/large?v=v2&px=999 "Screenshot 2024-09-24 at 3.22.25?PM.png")


author: Asheesh
body: ![Screenshot 2024-09-24 at 3.23.09?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/348938i0B8B7FB4E196D84F/image-size/large?v=v2&px=999 "Screenshot 2024-09-24 at 3.23.09?PM.png")


author: Bill Sheboy
body: In the advanced branch, it needs to split the values. Please see the original post for context.

* advanced branch:
  * smart value: {{varLoopValues.split(",")}}
  * variable name: varLoopVariable

Also as you create a rule, it can help to write values to the audit log to assess progress. I recommend adding the variable to the audit log immediately before the branch to confirm it contains what you expect:

* action: log
  * the variable contains: {{varLoopValues}}


author: Asheesh
body: Thanks, let me try


author: Asheesh
body: Bill,

Please find attached log message

![Screenshot 2024-09-24 at 10.35.41?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/349049iEC0B2FFC3CA436D1/image-size/large?v=v2&px=999 "Screenshot 2024-09-24 at 10.35.41?PM.png")


author: Asheesh
body: ![Screenshot 2024-09-24 at 10.38.14?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/349050i9BB49753A9FC6184/image-size/large?v=v2&px=999 "Screenshot 2024-09-24 at 10.38.14?PM.png")


author: Asheesh
body: Thanks a TON Bill, it's working.


author: Manoj Gangwar
body: Hi [@Asheesh](/t5/user/viewprofilepage/user-id/5493246) Welcome to the community!

You can use the IF Else condition

If count 1 then create 1 subtask

Else count 2 then create 2 subtasks

Else count 3 then create 3 subtasks

comments: author: Asheesh
body: Thanks, good idea. But if its say 7 then it may become clumsy.


author: Asheesh
body: Hello Manoj,

Looks there is some issue with current release of Jira Cloud, although I could add If-Else_Block, but while setting it up could not see an option to add else condition.

Could you please check.

Thanks

Asheesh


author: Manoj Gangwar
body: Please share the screenshot of IF block condition.


author: Asheesh
body: Image


author: Asheesh
body: Image


author: Asheesh
body: Unable to add an image.


Tags: cloud

jira-cloud