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.
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.
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:
Then the sum of weights would be this:
{{OrganizationWeight.entries.value.asNumber.sum}}
How this works:
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
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.