How to populate custom field value based on if else criteria using Automation

Laxmi Swamy June 22, 2024

Hi Community Members,

I have created two custom fields, customfield_1 (which can store single value from the list - High, Medium, Low) and another customfield_2.

I am trying to populate customfield_2 (number data type) using the Automation based on the values stored in customfield_1.

Automation rule is successfully running without any errors but customfield_2 is not getting populated with the required output value.

Please let me know the correct syntax or any other way that I can achieve the required logic without going for any third party plugins.

Thanks in advance.

 

Here is the alternate JSON codes tried in Advance field editing:

{ "fields": {

    "customfield_2": "{{#if(equals(issue.fields.customfield_1, \"High\"))}}50{{/}} {{#if(equals(issue.fields.customfield_1, \"Medium\"))}}25{{/}} {{#if(equals(issue.fields.customfield_1, \"Low\"))}}10{{/}} {{#else}}0{{/}}"

  }

}

-----

{ "fields": {

    "customfield_2": "{{#if(equals(issue.fields.customfield_1, "High"))}}50{{/}} {{#if(equals(issue.fields.customfield_1, "Medium"))}}25{{/}} {{#if(equals(issue.fields.customfield_1, "Low"))}}10{{/}} {{#else}}0{{/}}"

  }

}

-----

{ "fields": {

    "customfield_2": "{{#if(equals(issue.customfield_1, \"High\"))}}50{{/}} {{#if(equals(issue.customfield_1, \"Medium\"))}}25{{/}} {{#if(equals(issue.customfield_1, \"Low\"))}}10{{/}} {{#else}}0{{/}}"

  }

}

-----

{ "fields": {

    "customfield_2": "{{#if(equals(issue.customfield_1, "High"))}}50{{/}} {{#if(equals(issue.customfield_1, "Medium"))}}25{{/}} {{#if(equals(issue.customfield_1, "Low"))}}10{{/}} {{#else}}0{{/}}"

  }

}

3 answers

3 accepted

2 votes
Answer accepted
Tommaso Gionfriddo _Teklada_
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.
June 23, 2024

Hi @Laxmi Swamy

Welcome to the Atlassian Community!

I would also recommend avoiding using the advanced field json, however I think that the most future proof option is to use the (relatively new) lookup table functionality to define the relationship between the value in customfield_1 and customfield_2.

This allows for up to 200 possible values in customfield_1 in only 3 steps.

  1. When: Value changes for customfield_1
  2. Then: Create lookup table
    Screenshot 2024-06-23 at 10.58.17.png
  3. Then: Edit issue.
    1. Field: customfield_2
    2. Value: {{relationship.get(issue.customfield_1)}}

 

Laxmi Swamy June 23, 2024

Thanks Tommaso, tried the above solution it works like a charm. The only thing I need to cover is if I want to assign '0' value in case if the customfield_1 has blank/empty value (instead of High, Medium, Low values) as it is an optional field for the users to enter.

Tommaso Gionfriddo _Teklada_
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.
June 24, 2024

Hi @Laxmi Swamy ,

For this base case you can simply add a default to the smart value, as per this documentation. The value will be output when nothing is returned by relationship.get().

Your edit issue value should now be {{relationship.get(issue.customfield_1)|0}}

 

Laxmi Swamy June 24, 2024

Thanks Tommaso, for your support.

Kirk Acklin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 2, 2024

Ahoy ahoy @Tommaso Gionfriddo _Teklada_ This looks like a great place to start on a issue I'm trying to solve.  How would you recommend taking this and making it a 3-D lookup? 

I have three fields: customfield_1, customfield_2, customfield_3.  Each one has a text value (from a dropdown list) that I'd like to turn into a number 1-5 (1-4 for customfield_3): customfield_1.value1 = 1, customfield_1.value2 = 2, etc.

After finding the number for each custom field, I'd like to add them together to get a composite score: customfield_1.score + customfield_2.score + customfield_3.score = customfield_4

 

My end goal is for that customfield_4 to then have its own lookup table (or if/else statement) that sets a Priority dropdown based on the score range: 3-5 = Critical, 6-8 = High, etc.

 

Thank you for any help and thoughts.  :)

Kirk

1 vote
Answer accepted
Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2024

Hi @Laxmi Swamy

Can I recommend something a bit simpler? Rather than putting the code directly into the JSON, use more of the visual aspects to create automation flows. Here is what I would do for your solution.

  1. Trigger: Whatever you desire
  2. Condition: IF ELSE
    1. IF Condition: Issue fields condition
      1. Field: customfield_1
      2. Condition: equals
      3. Value: High (it should be a dropdown for you)
    2. THEN: Add an action: Edit issue
      1. Field to edit: customfield_2
      2. Value: 50
    3. ELSE Condition: Issue fields condition 
      1. Field: customfield_1
      2. Condition: equals
      3. Value: Medium (it should be a dropdown for you)
    4. THEN: Add an action: Edit issue
      1. Field to edit: customfield_2
      2. Value: 25
    5. ELSE Condition: Issue fields condition 
      1. Field: customfield_1
      2. Condition: equals
      3. Value: Low (it should be a dropdown for you)
    6. THEN: Add an action: Edit issue
      1. Field to edit: customfield_2
      2. Value: 10

Following this your customfield_2 will be updated :) 

Laxmi Swamy June 23, 2024

Thanks Jovin, for your support. The above solution is working as expected.

0 votes
Answer accepted
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2024

@Laxmi Swamy -

To supplement @Jovin suggested, can you verify that the customfield2 is exposed to your project in question (meaning the context for the custom field is configurated properly).

I would recommend the triggering event should be "Field value changed" for all issue operations.  In your rule, then setup the If/else condition to check for customfield1 value and then edit issue option to set the customfield2 value.

Hope this also helps.

Best, Joseph Chung Yin

Laxmi Swamy June 23, 2024

Thanks Joseph, I will use the same. Does it also covers the use case for Issue Creation as well.

Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2024

It should.  However, you may want to add "Re-fetch issue data" action before your edit issue action.

Hope this helps.  If my suggestion helped you, please click on "Accept answer" when you have a chance, so others with similar asks will see this posting as an answered one.

Best, Joseph

Suggest an answer

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

Atlassian Community Events