Jira Automation - Use Advanced Branching to loop through Organizations on a ticket

G December 17, 2023

Hello, I am trying to create an automation rule that iterates on each organization added to a JSM ticket and add a certain weight on its basis. My rule should allow me to calculate some metrics based on how many clients asked for a certain request and the weight of each client. 

So, I created a lookup table within the automation rule. The table has all organizations that we deal with. I assigned some value to each organization to represent its weight. 
Then I created a "for each" branch where I should iterate on each organization within the field and add its corresponding weight within a custom field. 

Screenshot 2023-12-17 173703.png

Screenshot 2023-12-17 172649.png

For some reason the "for each" loop is unable to return any value from the lookup table. 

Noting that the field "customfield_10002" is the Organizations field on JSM

Example Use Case: 
A ticket is created by org1.
we added org2 and org3 to the ticket 
the lookup table has some weighting values for each organization: org1 = 1, org2 = 5, org3 = 6
end result: a custom field should have the sum of each weight (1+5+6) to represent the overall value of the request. 


If you have any idea what could be the issue that would be much appreciated.  

1 answer

1 accepted

3 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.
December 17, 2023

Hi @G 

You do not show the table lookup for your advanced branch variable, and I suspect it looks like this:

{{OrganizationWeight.get(Organization)}}

That will try to use the id value from the custom field, and not the value.  To use the value, try changing your advanced branch smart value to use this:

{{issue.customfield_10002.value}}

 

And also...if you are trying to later use that sum of weights to edit an issue, using the branch may prevent that from working in a predictable manner.  The reason is branches which could be on more-than-one-thing are run in parallel and asynchronously.  There is no guarantee of when they will complete, up until the last step of the rule.

This should be easy to solve, however iterators cannot "see" data outside of their scope.  And so if you iterated over your custom field selections, it cannot access the lookup table.

 

And so there are a couple possible work-arounds: do this with the table pre-checking the values or do this inline, with one large conditional statement.

The first way eliminates the branch and changes your lookup table to conditionally contain the weight values.  For example, the table could contain:

  • key: none with value: 0
  • key: org1 with value: {{#if(issue.customfield_10002.value.join(",").indexOf("org1").gte(0))}}1{{/}}
  • key: org2 with value: {{#if(issue.customfield_10002.value.join(",").indexOf("org2").gte(0))}}5{{/}}
  • key: org3 with value: {{#if(issue.customfield_10002.value.join(",").indexOf("org3").gte(0))}}6{{/}}

Then the sum of weights would be this:

{{OrganizationWeight.entries.value.asNumber.sum}}

How this works:

  1. The first row of the table is a dummy value to ensure at least 0 is returned
  2. Each other row looks for the organization in the values returning their weight
  3. Then we use the new table function to gather all the entries, and sum them

This whole thing could be done inline, by just concatenating all of those conditions.  The table may be better-ish if you have lots of organizations to manage.

 

A simpler variation of that is to just use text functions and math expressions:

{{#}}0{{issue.customfield_10002.value.join(" + ").replace("org1","1").replace("org2","5").replace("org3","6")}}{{/}}

 

Kind regards,
Bill

G December 18, 2023

Hi @Bill Sheboy,
I appreciate your support, your answer is very descriptive. Thank you.  

Your assumption is correct, I am using "{{OrganizationWeight.get(Organization)}}" and I was not referring to the value of the custom field. I added the value and gave it a try with the advanced branching but didn't get any results either. I believe this is related to your insight that the branches cannot "see" the values of the index table. 
I tried including the index table within the branch but then the rule has stopped from acting completely so I don't think that's a solution. 

I edited the index table to include the if statements you were referring to; I have 122 organizations so I thought the table approach would be better for later management. After editing the whole table the sum returned is always 0. (it didn't work). 

for reference this is an example on how it looked 
Untitled.png
with the value "{{#if(issue.customfield_10002.value.join(",").indexOf("kwentra Sales Team").gte(0))}}1{{/}}" 

I tried the single line statement with a couple of actual organizations but it returned the error

Token is empty: {{#}}0{{issue.customfield_10002.value.join(" + ").replace("kwentra Sales Team","1").replace("Serenity Heights ( Alma & Alpha )","5")}}{{/}}

I thought maybe if I begin the function with "{{#=}}" would solve the issue, I changed and this resolved the error but the value returned in the field is always 0 which indicates that the logic didn't work for some reason. 

Do you think there's something that I am missing here?

G December 18, 2023

Hi @Bill Sheboy , I figured out the problem! 

The Organizations field in Jira is considered the same as a user field; So using 

issue.customfield_10002.value

won't work but if you use 

issue.customfield_10002.name

everything works properly. 

I would like to thank you for your support as your logic in the automation was the main solution to my problem. 

Kind regards, 
George

Like # people like 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.
December 18, 2023

Well done, diagnosing the issue!  I should have confirmed the custom field type earlier.

As a future tip: smart values are name, spacing, and case-sensitive.  And the type impacts the specifics of how to use them in rules.  This how-to article can help identify the correct smart values for a field:

https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

Like G likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events