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

プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。

このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。

*Fisheye および Crucible は除く

要約

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.

環境

  • 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

ソリューション

ユースケース

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:
      • 重要
    • The field Vulnerability Likelihood which has the possible options below:
  • 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
    • URL から ID を取得します。これは、自動化ルールを設定するために必要なカスタム フィールド ID です。
  • Repeat the same steps for the other field Impact of Vulnerability

ルール構成

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



最終更新日: 2024 年 10 月 22 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.