Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Automation - using split on smart value to create multiple subtasks

David Washburn
Contributor
July 31, 2023 edited

I have a manually triggered automation rule. It pings OpenAI, and returns a smart value. This smart value has a pattern (like an array but not officially) and I'd like to know if I can split the value and create multiple subtasks from it. For example:

{{webResponse.body.choices.message.content}} will return Subtask1,Subtask2,Subtask3,Subtask4 via log.

So I wanted to use {{webResponse.body.choices.message.content.split(",")}} to separate them by commas and hopefully use them as new Subtask names and create subtasks from them.

Is this possible? I've attempted using the split function of smart values and haven't had luck.

 

Automation1.png

2 answers

1 accepted

0 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 1, 2023

Hi @David Washburn 

From what you describe, it seems that REST API call is already returning a list and not an array.

One simple way to test that is to try to iterate over it an write to the audit log this:

{{#webResponse.body.choices.message.content}}{{.}}{{/}}

If it writes the values you expect, you can then try using an advanced branch to create your subtasks:

  • first an assumption: you have a trigger issue to add the subtasks to...
  • action: your web request call
  • condition: check the status of the call
  • advanced branch: with the name of varSubtask and the value of {{webResponse.body.choices.message.content}}
    • action: create a subtask, referencing {{varSubtask}} as your Summary field

Kind regards,
Bill

David Washburn
Contributor
August 1, 2023 edited

Hey @Bill Sheboy thanks for the additional tips! I have a semi-working version now using some trial and error this morning, but there's one looming question which I fear I might already know the answer to.

Does Atlassian automation support and kind of iterating/while loop?

Ideally I'd like to:

  1. Request an AI generate suggested tasks based on the description of the epic
  2. Have the AI return the tasks separated by a comma or other special character
  3. Break those tasks out using split
  4. Iterate and create tasks under the epic until it finds no more
    • The AI might return 3 values (TaskName1,TaskName2,TaskName3) 
    • Or the AI might return 10 values (TaskName1 through TaskName10 etc)
    • I'd like the automation to loop until it finishes

I've successfully accomplished steps 1-3, but I have no idea how to create any kind of while loop, or iterate via automation and create subtasks until it detects no more.

For anyone looking this thread up later, the way I solved steps 1-3 were:

  1. Create a new variable (called responseSplit) using the webhook response response {{webResponse.body.choices.message.content.split(",")}}
  2. Then I could reference each task manually using {{responseSplit.split(",").get(0)}} for the first task. And {{responseSplit.split(",").get(1)}} for the second task.
  3. My first task has a [ in the name and my last task has a ] in the name. So I had to use special splits to remove those characters.
    • First is {{responseSplit.split(",").get(0).remove("[")}}
    • Last is {{responseSplit.split(",").get(4).remove("]")}}

But this method doesn't have looping, so it only works if I know exactly how many tasks are being returned. Right now I've asked the AI to only return 5, so I manually create 5 tasks in my automation and inject the task name using the split above. But it wouldn't work if we wanted the AI to return a dynamic number of tasks based on how many it thinks there should be.

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 1, 2023 edited

Yes: you may use advanced branching for that, as described below and in my earlier post:

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

Basically you name a branch variable and supply a source, such as a list, split/delimited text, or collection of issues.  There are limits for such branches, so read here to learn about the processing limits for automation rules:

https://support.atlassian.com/cloud-automation/docs/automation-service-limits/

 

Something key to know about automation branches:

  1. Branches on one-and-only-one thing (e.g., branch on current issue, or parent, etc.) are run in-line as if the branch did not exist
  2. All other branches, that could be on on more than one thing (e.g., advanced branches, on JQL, etc.) are run asynchronously and in parallel.  There is no guarantee of when the branch will complete, up to the last step of the rule.

Please consider the goal of your rule, as the #2 type often will not finish before the next rule steps after the branch.  So if you need some result based on the branch, consider other solution approaches than branching.

0 votes
David Washburn
Contributor
August 1, 2023 edited

For example, when I attempt to create new subtasks using {{webResponse.body.choices.message.content.split(",")}} it tries to jam the entire Subtask1,Subtask2,Subtask3 etc into the summary of the subtask. Looking for any kind of way to separate the split content into multiple smart variables.

Amish Khatri February 5, 2024

Do you mind showing your automation rule flow?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
atlassian, ace, atlassian community event, donation, girls who code, women in tech, malala fund, plan international, kudos, community badge, badge, atlassian badge, International Women’s month, International Women’s Day, women's month, women's day

10 for Change at Atlassian Community Events

Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!

Join an Atlassian Community Event!
AUG Leaders

Upcoming Jira Events