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

Branching over smart values in Jira Automation

46 comments

Alex F September 22, 2022

Hi @Bill Sheboy, thank you for your answer!

I re-read the documentation yesterday and found that the match() function actually returns not the first occurrence, but all occurrences as a collection (if there are more than one occurrences), so it works. There is a nuance - you still have to use the split() function in advanced branching (probably a bug), but, in the end, everything is ok.

Here's what it looks like:

2022-09-22_17-02-59.png2022-09-22_17-03-18.png

Or you can just try to use the following smart value in the advanced branching smart value field:

{{issue.comments.last.body.match("(\[~accountid:\S+\])").remove("[~accountid:").remove("]").split(",")}}

And now you can perform a separate action for each {{accountId}}.

Alex F September 22, 2022

I've found that you can use advanced branching inside an if/else construct, but you can't do the opposite. It's a pity that I can't branch with if/else inside advanced branching, it might make it easier to create advanced automations.

Perhaps someday this will be implemented 🤞

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.
September 22, 2022

@Alex F thanks for the information on the split/match versus match/split ordering, and I am glad to learn you got it to work.  At a minimum, it seems the documentation should indicate the function returns only text, and not a collection as stated, and so leading to using split later when needed.  If it was a collection, we should be able to immediately iterate over it.

FYI on the rule structure of branches and if/else, there is a hack which involves creating both at the same level and then drag-n-drop to what you want.  However that appears to be unplanned behavior so if you notice it I would avoid using that in a production rule.

Kind regards,
Bill

Like Darryl Lee likes this
Alex F September 22, 2022

@Bill Sheboy thank you for the hack, I tried to drag-n-drop if/else branch, but it can't be dragged 🤷‍♂️ All other elements move easily.

If it was a collection, we should be able to immediately iterate over it.

You're right, so I checked it carefully again and found that when you create an intermediate variable the collection is converted to text, so the best way to achieve the goal is to use match() function directly in advanced branching block (it just didn't work for me the first time, but now everything is ok):

2022-09-23_9-28-42.png

So you can just use the following expression in the advanced branching block and then you can do whatever you want with each {{accountId}}:

{{issue.comments.last.body.match("(\[~accountid:\S+\])").remove("[~accountid:").remove("]")}}
Like Bill Sheboy likes this
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.
September 23, 2022

Hi @Alex F 

Another tip: when creating a variable (or naming one in advanced branches) use a name that is unlikely to match another smart value.  That can help with maintenance and avoid the potential of collision with existing smart values from objects.  For example, I always the prefix "var", such as "varAccountId".

Like Alex F likes this
perla.miranda October 11, 2022

@Bill Sheboy Hi, I asked a question earlier this year which is above in the thread. The answer was working perfectly fine. This is what I've had since then, but somehow, stopped working this week. Do you have any idea what could've caused this or how to fix it? It's currently messing up our process now and users are going in and manually editing it now.

Goal, create subtasks that are named accordingly such as "Module 1", "Module 2", etc according to a number given in a previous field.

Currently what started happening yesterday, If module count is X (e.g. 25), each subtask is named "Module 25". Instead of starting at 1 and increasing accordingly. Unsure what to do.

 

{{#varLoopValues.rightPad(varLoopValues.length.plus(issue."Module Count"), "X").remove("NULL").replaceAll("X","X,").substringBeforeLast(",").split(",")}}{{#=}}{{index}}+1{{/}}{{^last}},{{/}}{{/}}
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.
October 11, 2022

Hi @perla.miranda 

I just retested with my original example rule and it works as before.  I suspect that your Module Count field or automation rule have changed to cause the difference.

As this may take a bit of back and forth to resolve, please consider creating a new question for this, posting images of your complete rule and the audit log, and linking to this thread.  If you mention me in that question I will see it when you post it.  Thanks!

Until then, perhaps write the above smart value expression to the audit log to see what shows.  That one drives the advanced branch looping; if it does not show the values increasing you can isolate the problem a bit.

Kind regards,
Bill

Darryl Lee
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 4, 2023

Hey @Sam Harding and @Simmo - it's been a few years, and I cannot find a feature request/suggestion to "Bring Advanced Branching (over Smart Values)" to Server/Data Center.

Sidenote: After almost 3 years, it was cool to find movement on this:

JIRAAUTOSERVER-53 - Bring the Lookup Issues action to Automation for Jira Server/Data Center 

So is there a similar issue for Advanced Branching?

Thank you!

Like # people like this
Simmo
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 7, 2023

Hey @Darryl Lee,

Afraid that Sam and I have no idea :) The server team is a bit of a black box to us since we split. 

Can you just raise the said suggestion?

Eran Nir July 30, 2023

@Sam Harding 

Hi,

When moving a Story (issue type) ticket to Done status, I have a popup window opens.  
I would like to add to this window 2 questions like:
*Is it A? (Yes/No)
*Is it B? (Yes/No)

If one of the questions is answered with Yes and “Done” (the window's button) is clicked, then I need:


  • 2 new tasks (issue type= Task) should be automatically created and attached to this origin Story (ticket)

  • Tasks name should be the lifter name

  • The question text (e.g "Is it A?") that was answered Yes, should be in the description or any other field in the task

  • One of the tasks should be set with the label (Label field) “Security” assigned to a specific user.

  • The second task should be set with the label (Label field) “Privacy” assigned other specific user

Note: if both questions are answered Yes, then 4 tickets should be created (2 for each).
1. Which fields should I use for the Window's questions?
2. Can these functionalities be supported? and how?

Due to the fact we are using A4J on the lite version we don't have those options.

I tried using ScriptRunner should work?

James Smith February 5, 2024

@Bill Sheboy I've just come across your smart value solution for looping, it's exactly what I need, however I'm not able to get any results using it.

The field I am using is called "Number of parts impacted" rather than XCount, but the idea is the same, I want to loop through the number of impacted parts input and then depending on the number do something that amount of times (in this instance create that many new issues).

But the following code for the variable gives me a blank result every time regardless of the value in the Number of parts impacted field.

{{varLoopValues.rightPad(varLoopValues.length.plus(issue."Number of parts impacted"), "X").remove("NULL").replaceAll("X","X,").substringBeforeLast(",")}}

I was wondering if you might be able to shed some light? Thank you.

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.
February 5, 2024

Hi @James Smith 

Without seeing your entire rule for context, the most likely cause is the smart value for your custom field is incorrect.  When the wrong one is used, it can silently collapse to null in rules without any errors shown.

Smart values are name, spacing, and case-sensitive.  And often the smart value does not match the displayed field name on the issue views.  To identify the correct smart value (and custom field id) for any supported fields for automation rules please try these steps:

  • identify an example issue which has your field(s)
  • call a REST API function with a browser to search for your issue:
https://<yourinstanceurl>/rest/api/2/issue/<issuekey>?expand=names
  • search on the page for your field, such as with CTRL-F
    • if you find the field, you will also find the smart value, custom field id, and structure / attributes it has
    • if you do not find the field, it is not supported by automation rules

Once you have the smart value or custom field id, please update your expression and re-test.

Kind regards,
Bill

Like James Smith likes this
James Smith February 5, 2024

Thanks @Bill Sheboy 

I've found the smartvalue, though I'm fairly sure that using issue.Number of parts impacted isn't the issue.

For reference, using the 

customfield_10055

 didn't help.

It's odd.

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.
February 5, 2024

Would you please post an image of your complete rule, images of the relevant actions, and the audit log details showing the execution?  Those may provide more context to explain this symptom.

James Smith February 6, 2024

Screenshot 2024-02-06 080848.pngScreenshot 2024-02-06 080855.pngScreenshot 2024-02-06 080903.pngScreenshot 2024-02-06 080839.png

@Bill Sheboy See screenshots. I've kept the rule pretty simple for now so I can get it right and then use it for something more complex.

Thanks for the help so far btw.

James Smith February 6, 2024

In fact I just tested to make sure that either {{issue.customfield_10055}} or {{issue.Number of parts impacted}} gives me a value in the comment and it does. So it's definitely not falling over on the field value.

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.
February 6, 2024

@James Smith -- I just saw your post in the other thread, and it appears you discovered the missing action to initialize the created variable to NULL.  Is that correct?

Thanks!

Maximilian Floß February 20, 2024

@Bill Sheboy 

Hi, could you please explain to me how do I do advanced branching on lists: 

I have a lookupissues list with two issues inside and I want to do actions on each of the two issues of the lookupissues list separately. 

The audit log of my lookupIssues list is the following: 

TM-50, TM-49

But the two issues are not getting updated when i try to use lists as advanced branching: 

image.png

 

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.
February 20, 2024

Hi @Maximilian Floß 

Advanced branching helps to loop over anything referenced from a smart value expression, such as from a lookup issues result.  However, my understanding is the rule does not recognize the entity from the advanced branch as an issue within scope of the rule, and so actions like Edit Issue cannot act upon it.

Contrast that to a branch on parent, linked issues, JQL, etc., where we do not provide a Variable Name because within the branch, {{issue}} refers to the currently looped-to issue.

Without seeing your entire rule, consider instead using a branch on JQL for this case, as the same JQL that worked for the lookup can be used to drive the branch.

Kind regards,
Bill

Maximilian Floß February 21, 2024

@Bill Sheboy 

image.pngimage.png

See my screenshots.

Manual trigger which is triggered from an Epic and the attribute "Meeting required" should be edited on Epic, their underlying tasks and their underlying subtasks. 

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.
February 21, 2024

Hi @Maximilian Floß 

Based on your rule image, that cannot work for your scenario:

  • it is unclear what the initial branch is using as a source, as the entire rule is not in the image
  • a lookup issues action is inside the branch, is not used, and will not be available after a branch: things which are created inside of the branch (e.g., the lookup) not longer exist outside
  • to do what I suggested earlier, change the branch type to use JQL (not the lookup), to directly iterate over the issues to edit

 

I recommend creating a new question, perhaps linking to this thread, including in your question:

  • what problem your rule is trying to solve; that is, "why do this"
  • an image of your complete automation rule, in one image
  • images of any relevant triggers, actions, conditions, branches
  • an image of the audit log details showing the rule execution
  • explanation how the rule is not working as expected

Creating a new question will ensure more people see it to offer suggestions, as only people following the older threads will see them.

Thanks!

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events