Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,093
Community Members
 
Community Events
165
Community Groups

Automation if statement

Hi,

Having issues with if statements.

Goal: I've got a custom field with checkboxes, so imagine the custom field is "Technologies". There are 3 checkboxes and the user can select any of the 3 and also more than 1 if they want. This field is found in a task issue. When the user creates the task issue, I want to automatically create a subtask issue for each of the ones that were selected. Also, I've got another custom field, let's say "Number of times that we want to repeat it". If this value is set to "2", I want to create 2 of each subtasks for X technology. So let's say all technologies were selected, we would get two subtasks of technology 1, two subtasks of technology 2, and two of technology 3. 

What's working?: For loop is working, no issues here.

Problem: With the automation, if the user selects all 3 technologies that exist, there are no problems and all subtasks are properly created. If the user selects only the first one, there are no problems and all subtasks are properly created. If the user selects the first and second option, there are no problems and all subtasks are properly created. If the user selects the first option and the third option, only subtasks for the first option are created. If the user only selects the second and third option, no subtasks are created.

Assumption: During automation, when going through the if statements, it seems that as soon as it reaches an if statement that is not true, then it breaks from the loop instead of continuing to the next if statement. 

Structure: Currently, I've got the following structure (pseudo):


When creating an issue
{if the issue type is task}
{then for each value X field (e.g. Number of times that we want to repeat it = 2)}
{if technology 1 is selected}
{then create subtask for technology 1}

  {if technology 2 is selected}
{then create subtask for technology 2}

{if technology 3 is selected}
{then create subtask for technology 3}

 

Technically, I think the "then" in the "if" statements should be indented, but I don't think automation is allowing me to create another layer, or I'm not sure which action to use for the if statement but the current one is not allowing me to place the "then" inside of the "if", and even then I'm not sure if that would work.

 

Attached is a screenshot. Also, if the issue is the amount of nesting allowed, can you please provide me with a different approach with automation to achieve the same goal? I'm in a rush with this and can't let this go out with bugs :/

if_statement.png

 

 

2 answers

1 accepted

I found the solution. Not ideal because it's slower but it works.

 

I read about the restrictions in branching and realized it really wasn't possible to create and if/else nor another for loop inside of a current for loop. So thought about how to restructure it.

 

So what I did instead, is I did a for loop for each checkbox. Before, I had one for loop and wanted to check all boxes at once for efficiency purposes, but the if would break out the for loop if one if statement was false. Ideally, the if/else would've worked perfectly fine in here or another for loop with create subtasks but neither of these where available.

So entering the for loop, doing only one if, so even if it's false it breaks out of the for loop but proceeds to the next for loop.

Here is the final rule and the output that works even when some boxes are unchecked. Again, a lot slower having to do a for loop multiple times but works.

 

final_solution_for_use_cases.png

Output when the count is set to 2:
use_case_output.png

I appreciate the help and at least learned about more functionalities and more restrictions with automation. Thanks!

I did try doing the if statement first and then the for loop so that we don't loop unless the if statement is true, but again if/else was not available inside of another if/else statement that I have, and using if statement alone would break the rest if one was false.

For someone who doesn't start their automation with an if/else statement, they may be able to use if/else and then for loop, which would be more efficient and I would recommend.

I personally need and if/else for another reason. So I have to do unnecessary loops.

1 vote
Stefan Salzl Community Leader May 03, 2022

Hi @perla.miranda ,

as far as a condition returns ‚false‘ the rule breaks.

There is also possibility of if/else. Did you try this? From my point of view this should work.

 

Best
Stefan

That's why I originally wanted to do but the problem is that I don't have the option to add if/else under a for loop. Any other ideas?no_if_else.png

Stefan Salzl Community Leader May 05, 2022

Got it.

regarding your first problem I guess I got a pretty simple solution that doesn´t need any if/else block. The branch itself takes the list of checked checkbox values and only creates subtasks for those (see screenshot)

image.png

image.png

 

Regarding your second requirement I´m not sure if A4J is capable of changing the number of subtasks that dynamically. (at leaset I don´t know any solution for this yet).

 

Best
Stefan

Stefan Salzl Community Leader May 11, 2022

Hi @perla.miranda 

Any feedback?

Best
Stefan

Hi Stefan! 

 

I think this might work. I'll give it a try.

 

But what exactly is "Checkbox 1" in the smart value of advanced branching? Is that the name of the of the custom field that contains checkboxes? 

For some reason, I'm unable to add spaces there, but I will type it somewhere else with spaces and then paste it in there.

 

Thanks,

Perla

Stefan Salzl Community Leader May 11, 2022

hi @perla.miranda ,

„Checkbox 1“ is the name of my customfield of type „checkbox“ and has several options to choose/check. Isn‘t that the setting you‘ve got on your side?

And really strange you cannot add space in that field.

To avoid any confusion:

could you please provide screenshots of an issue containing the checkbox and also of the rule component in which you try to add the smart value but are not able to write spaces?

Best
Stefan

Stefan Salzl Community Leader May 17, 2022

Hi @perla.miranda ,

Could you already try out the suggested solution? Please let us know if this was helpful.

Best
Stefan

Hi Stefan, 

 

The problem is that I already have one for loop. And I don't have the option to add another for loop inside of the for loop.

 

My current for loop is the counter for how many times I want it to create each subtask. If you take a look at the original image in the post, that for loop is working correctly if all checkboxes are selected. But again breaks from the for loop if any of those are not true.

 

So it sounds like with the suggestion above I would be able to automatically create subtasks for the checkboxes that are checked, but I need that inside the counter of how many times I want it to run that task. So in this case, the suggestion would create the subtasks needed but not as many times as I'd like it to.

It almost seems like I'm limited to the things that I can do inside of a for loop.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you