Automation For Jira - Using complex IF/ELSE conditional logic with smart values to convert select list fields into numbers

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Automation For Jira's official documentation about Smart Values - Conditional Logic explains how to execute an action if an condition is verified. However, it does not explain how to:

  • execute an action if the condition fails (=ELSE condition)
  • execute an action in case of multiple IF/ELSE conditions

The purpose of this article is to explain how to write a rule using Smart Values to implement a complex conditional logic which has multiple IF/ELSE conditions.

Environment

  • Jira Data Center Only (not applicable to Server licenses)
  • Applicable Jira / A4J (Automation for Jira) versions which include the Create Variable action:
    • Jira 9.11.0 and any higher version (this Jira version ships with A4J 9.0.1)
    • OR Jira 8.20.0 and any higher version, in combination with A4J 9.0.1 or any higher version

Solution

Use Case

The use case of this rule is the following:

  • A Jira project has 2 Select List (single option) fields that are related to Vulnerabiliies:
    • The field Impact of Vulnerability which has the possible options below:
      • Critical
      • High
      • Medium
      • Low
    • The field Vulnerability Likelihood which has the possible options below:
      • High
      • Medium
      • Low
  • This project also has Number field called Risk score, which will be calculated based on the logic below:
    • The Impact of Vulnerability field needs to be converted into a number as follows
      • Critical → 20
      • High → 15
      • Medium → 10
      • Low → 5
    • The Vulnerability Likelihood field needs to be converted into a number as follows:
      • High → 15
      • Medium → 10
      • Low → 5
    • The Risk score field needs to be calculated as the sum of the 2 numbers above:

      Risk Score = Numerical value of "Impact of Vulnerability" + Numerical valuer of "Vulnerability Likelihood"

Preliminary steps - Get the Custom Field IDs

Before configuring the automation rule, you need to first identify the ID of the 2 Select List custom fields, since this ID will be different depending on the Jira environment:

  • Go to ⚙ > Issues > Custom Fields
    • Search for the Vulnerability Likelihood custom field, and click on ... > View
    • Get the ID from the URL: it is custom field ID that is needed to configure the automation rule
  • Repeat the same steps for the other field Impact of Vulnerability

Rule configuration

The automation rule will be configured like this:

New Trigger: "Field Value Changed"

  • Fields to monitor for changes: select the 2 Select List custom fields Impact of Vulnerability and Vulnerability Likelihood

New condition: "Issue fields condition"

  • Field: "Impact of Vulnerability"
  • Condition: Is not empty

New condition: "Issue fields condition" 

  • Field: "Vulnerability Likelihood"
  • Condition: Is not empty

New action: "Create Variable"

  • Variable Name: impact
  • Smart Value:  (warning) make sure to replace XXXXX with the Custom Field ID of the field Impact of Vulnerability

    {{if(equals(issue.customfield_XXXXX.value, "Critical"), "20", if(equals(issue.customfield_XXXXX.value, "High"), "15", if(equals(issue.customfield_XXXXX.value, "Medium"), "10", if(equals(issue.customfield_XXXXX.value, "Low"), "5"))))}}

New action: "Create Variable"

  • Variable Name: likelihood
  • Smart Value:  (warning) make sure to replace XXXXX with the Custom Field ID of the field Vulnerability Likelihood

    {{if(equals(issue.customfield_XXXXX.value, "High"), "15", if(equals(issue.customfield_XXXXX.value, "Medium"), "10", if(equals(issue.customfield_XXXXX.value, "Low"), "5")))}}

New action: "Edit Issue"

  • Choose fields to set...:
    • Select the field Risk Score
    • Copy the expression below:

      {{#=}}{{impact}} + {{likelihood}}{{/}}

Screenshot showing the rule



Last modified on Oct 22, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.