I have multiple custom fields that are drop downs. I want my automation to look up the custom fields and if it equals one of the drop down value, I want to assign it a numeric value, such as 30. So I created a variable and assigned the value there. This will be done for a few custom fields. Then I want it to sum up the values.
So I created this automation (paraphrasing the fields to keep this short)
If Custom_field Q1 = A1
Then Create a variable - qone = 30
Else
If Custom_field Q1= A2
Then Create a variable - qone = 20
If Custom_field Q2 = A1
Then Create a variable - qtwo= 20
Else
If Custom_field Q2= A2
Then Create a variable - qtwo= 10
Then Edit Issue
Edit Custom Field
{#=}}{{qone}}+{{qtwo}}{{/}}
However, I am not getting any values to appear. When I try to log it, the value is blank in the audit log like it is not actually creating the variable. If I do not use an If/Else and only and if, it was working, but I need it to check the value of the Custom Field. Can you tell me what I am doing wrong?
Please disregard my question. I figured it out myself. I have to create the variable at the start to use them outside their branches
Hi @Philip Ng
Well done solving your own question!
And...have you tried using Lookup Tables to solve scenarios like this: https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Create-lookup-table
It will make the rule shorter and often easier to maintain. For example, your rule could be reduced to:
{{#=}} 0{{mapQuestionOneValues.get(issue.customFieldQ1.value)}} + 0{{mapQuestionTwoValues.get(issue.customFieldQ2.value)}} {{/}}
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the suggestion. This helped as I was hitting the 65 component limit. I was able to create lookup tables for a bunch of values which lowered my component count by a lot. The only time I couldn't use a look up table was when the keys had some non-alphanumeric values such as % and commas.
For a separate automation I am working on, is it possible to use lookup tables where I have a custom field which contains a calculated numeric value that will change per issue.
Let's say if the Custom field value is between 0-20, return a value of low, 21-40 return a value of medium, 41+ returns a value of high.
Right now, I have if else components doing this. Just wanted to know if there is a more optimal way of doing it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When mapping a range of numeric values to a lookup table, each value would need to be provided as a key. For such cases, a conditional / logical expression with math tests may be better.
For example, assuming the custom field is a number type:
{{#if(and(issue.myCustomField.ge(0), issue.myCustomField.le(20)))}}low{{/}}{{#if(and(issue.myCustomField.ge(21), issue.myCustomField.le(40)))}}medium{{/}}{{#if(issue.myCustomField.ge(41))}}high{{/}}
The example you describe could also be done with a formula, such as with integer division by 20 using that as the key in a lookup table.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for that example. I was able to get it to work when the custom field contained only a number. I am learning a lot from your suggestions and help as always.
However, if I try to use a custom field that contains a number and text, it doesn't seem to work. I have tried creating a variable to remove the text and then in the math test also use the asNumber function but it doesn't return a value. If I just have it output the variable, it does show just the number. It just doesn't work when I try to start doing math with it.
Example:
Custom field value is "8 points"
I am trying a math test where if the variable is less than 10, output Lvl 7
I created a variable and removed the text " points".
{{customfield_11867.remove(" points")}}
Then I went to log the result of
{{#if(and(urgLvl.asNumber.lt(10)))}}Lvl 7{{/}}
But it returns no value. Can you provide some assistance? I am enjoying learning these interesting Jira automation tricks. Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First thing: well done experimenting to extract your number from the value!
For the expression you are showing, it uses the and() function but there is only one parameter rather than the two expected. Please try removing the and() when only one test is required:
{{#if(urgLvl.asNumber.lt(10))}}Lvl 7{{/}}
As an FYI...created variables can be converted with asNumber for use in a math expression, but not for all others. To learn what does (or does not) work for variables as numbers, please see this article I wrote on the topic:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much as always. I had actually tried your example before posting here, and now I see what I did wrong after comparing yours to what I had in mine. For some unknown reason, I added a period in my variable in the math test ({{#if(urg.Lvl.asNumber.lt(10))}}Lvl 7{{/}}). -_- You keep looking at something for a while and your eyes start to play tricks on you. Lesson learned.
I also read your article. Quite informative. Much easier to understand than the Atlassian docs they produce.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.