Using conditional logic in variables to create "Score"
Asked by Brian Gauthier:

I'm trying to use variables to associate numercial values to values in other fields. I have four variables. Reach, Urgency, Impact, and Executive Importance. Each of those fields has selections such as "High", "Medium", "Low". I want to associate numerical values to those selections for each of the 4 fields and then apply a summation to get a total score.

I've tried using code like this in the smart value section of creating a variable , but I'm getting an error. Here's an example of trying to apply this for the reach variable (customfield_10060)

Name: reachValue

SmartValue:

{{#=}}

{{#if(equals(issue.customfield_10060, "Very High"))}}13

{{else}}{{#if(equals(issue.customfield_10060, "High"))}}8

{{else}}{{#if(equals(issue.customfield_10060, "Medium"))}}5

{{else}}{{#if(equals(issue.customfield_10060, "Low"))}}3

{{else}}{{#if(equals(issue.customfield_10060, "Very Low"))}}1

{{else}}0{{/}}{{/}}{{/}}{{/}}{{/}}

{{/}}

Any ideas what would make this work?


Answers:
author: Bill Sheboy
body: Hi [@Brian Gauthier](/t5/user/viewprofilepage/user-id/5349757) -- Welcome to the Atlassian Community!

As others have noted, that is the incorrect syntax for a smart value condition as {{else}} is not valid.

For this type of rule, I recommend using a Lookup Table to convert the values to the numbers: <https://community.atlassian.com/t5/Automation-articles/Update-Create-lookup-table-action-improvements/ba-p/2427798>

When you do that, use the value attribute of the fields so the display value is the key. For example:

* action: Lookup Table
  * name: varReachToScore
  * row:
    * key: Very Low
    * value: 1
  * row:
    * key: Low
    * value: 3
  * row:
    * key: Medium
    * value: 5
  * row:
    * key: High
    * value: 8
  * row:
    * key: Very High
    * value: 13
* example action to use the lookup

```
{{varReachToScore.get(issue.customfield_10060.value)}}
```

Create a Lookup Table for each conversion value. Then if you wanted to sum that, that might be this, **substituting in your correct custom fields**:

```
{{#=}}
   {{varReachToScore.get(issue.customfield_10060.value)}}
 + {{varUrgencyToScore.get(issue.urgency custom field.value)}}
?+ {{varImpactToScore.get(issue.impact custom field.value)}}
 + {{varExecutiveImportanceToScore.get(issue.executive importance custom field.value)}}{{/}}
```

As a observation about your calculation, having a parameter such as "Executive Importance" is often an indication / smell of a process problem, where opinions rather than repeatable methods are impacting product management. Perhaps discuss that with your team coach and product management team.

Kind regards,  
Bill


author: Boris Zozoulia
body: Hello [@Brian Gauthier](/t5/user/viewprofilepage/user-id/5349757)

As per the docu - u have referenced  
\> The smart values listed on this page can be used with actions where text fields are involved, such as the [**Add comment**](https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Jiraautomationactions-Addcomment) or [**Send email**](https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Jiraautomationactions-Sendemail) actions. They can be used to **print outputs based on conditional logic** such as if or and statements.

In other words - I understand - conditional logic smart values cannot be used in the creation of smart variables.

and then also - the "else" problem, mentioned by [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)


author: Trudy Claspill
body: Hello [@Brian Gauthier](/t5/user/viewprofilepage/user-id/5349757)

Welcome to the Atlassian community.

What is the error you get?

Looking at the [documentation for conditional logic](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/) I don't see any indication that {{else}} is supported. Did you see that syntax in an example somewhere?


Tags: cloud

jira-cloud