Automation to update custom field "Score" based on custom multi-select field "Scoring parameters"
Asked by Finn Harsfort:

I have a custom field called Score that should always reflect the scoring of the issue based on some scoring parameters which is kept in another field "Scoring parameters" (multi-select custom field). To keep it simple, lets assume only 3 possible vaules for scoring:

- Option A (with a weight of 40%)

- Option B (with a weight of 30%)

- Option C (with a weight of 30%)

If only Option A of the scoring parameters is selected, the Score should be 40.

If Option A+B is selected, the score should be 70 (40+30)

If all options are seleced the score is 100.

How do I setup an automation rule to calculate a new Score value every time the Scoring parameters are changed ?


Answers:
author: Bill Sheboy
body: Hi [@Finn Harsfort](/t5/user/viewprofilepage/user-id/701830)

I believe you can do this with a single math statement and the filtering of smart value lists feature:

* <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/>
* <https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588>
* <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/>

Inside of your math operation, use your field and filter/check for the specific value and multiply by your weight, summing the results. One tip to help is using a default value of 0 for when a value is absent.

Kind regards,  
Bill

comments: author: Finn Harsfort
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) Thanks Bill, but Im afraid I need a bit more guidance. I assume I just keep the first If condition (Scoring paramter has changed) and then 1 single action to update the score field using a math expression. But the math expression is causing me a headache. How do i iterate the scoring paramters and sum up the values conditionally ? Can you share just a bit of this logic to get me started on right track ?


author: Bill Sheboy
body: No problem and glad to help!

For your use case with just a few options, there is a simple way to do this with the match() function. For example:

```
{{#=}} {{#if(exists(issue.yourCustomFieldNameOrID.match("Option A")))}}40{{/}}
 + {{#if(exists(issue.yourCustomFieldNameOrID.match("Option B")))}}30{{/}}
 + {{#if(exists(issue.yourCustomFieldNameOrID.match("Option C")))}}30{{/}}
 {{/}}
```


author: Bill Sheboy
body: My mistake; that one does not work! I'll experiment with it a bit to see what is not working. Until then, please continue, perhaps using created variables to sum up.


author: Finn Harsfort
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) I also found out the hard way :) I really appreciate your help Bill and hope you find a solution. So thanks a lot so far. I am also trying some alternatives, but still without succes.


author: Bill Sheboy
body: Here's one that works, using list iteration and smart value, in-line conditions (filtering) with equals().

The spacing and null-handling (including the leading 0) are key to prevent errors in the math operation.

{{#=}}0{{#issue.customfield_10063}}{{#if(equals(value, "Option A"))}} + 40{{/}}{{#if(equals(value, "Option B"))}} + 30{{/}}{{#if(equals(value, "Option C"))}}+ 30{{/}}{{/}}{{/}}

How this works...

* a math expression wraps everything, with a minimum of returning a zero (0)
* inside is a list iterator on the multiple-select field
* with a condition test on the {{value}} to dynamically add the value, such as " + 40"
* any values which return false (i.e. null) disappear from the expression

Please let me know if this one helps.


author: Finn Harsfort
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) This works like a dream.

Thank you so much for your help on this issue !!!


author: Dan Tombs
body: Hi [@Finn Harsfort](/t5/user/viewprofilepage/user-id/701830)

One of the easiest way to do this is to create 3 additional number fields and default value is 0. then create an automation that looks for any update to the score parameter field. Have an if else statement that looks for the different values in the field. If score parameter contains X. Then in 'X number field' change value to Y.

Then at the end of the automation - outside of the if else statements. add an action to refetch issue data then add an edit issue action to add all of the number fields back together.

If you need some further help let me know :)

Dan

comments: author: Finn Harsfort
body: Hi [@Dan Tombs](/t5/user/viewprofilepage/user-id/4172448)

I understand what you mean, but we have much more than 3 scoring parameters, so that would be a lot of custom fields to add, but perhaps the only way...

I have been playing around with:

- initilly set score to 0 when the Scoring parameters changes

- adding an if statement for each scoring parameter value:

(if option A the increment Score with 40, if B then increment with 30 etc..

This wont work since Score value is not "kept" on.

I also tried to use create a Variable but cant find a way to update this variable and then assign it to Score as the last step.

I hope it is possible to do in some way, so I dont have to create all those addition fields, but I can see that would work.


author: Dan Tombs
body: Hi [@Finn Harsfort](/t5/user/viewprofilepage/user-id/701830)

Are you refetching issue data in between the if statements. Screenshot the rule and I can try and help see what you have to get it working.

Dan


author: Finn Harsfort
body: hi [@Dan Tombs](/t5/user/viewprofilepage/user-id/4172448) ,

No I dont refetch issue data but also tried that without succes. But then it wont "remember" the new value for Score assigned in previous steps. I wish there was a way (using a math formula perhaps, to just assign the new value for the "Score" field based on which options are selected in the "Scoring paramters" field.

Here is a snippet of the automation rule:

![Screenshot 2022-08-15 145523.png](https://community.atlassian.com/t5/image/serverpage/image-id/211071i0D89365E287160CB/image-size/large?v=v2&px=999 "Screenshot 2022-08-15 145523.png")

![Screenshot 2022-08-15 145736.png](https://community.atlassian.com/t5/image/serverpage/image-id/211072i1E4205E24780B09A/image-size/large?v=v2&px=999 "Screenshot 2022-08-15 145736.png")

The last action if for the first options and etc. for the rest