Convert Very High, High, Medium, etc. to number
Asked by Gustavo Moraes:

Good morning, guys!

I'm trying to create a "Score Point" field based on the other three fields I have (Value, Impact, and Effort).

I have already created the field Score Point as a Number Field, and I'm trying to use the script below on my automation:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/346587i44FD6970B6496C63/image-size/large?v=v2&px=999 "image.png")

```
// Initialize numeric variableslet numericValue = 0;let numericImpact = 0;let numericEffort = 0;// Convert 'Value' to numericif ({{issue.customfield_10381}} == "Very High") {  numericValue = 5;} else if ({{issue.customfield_10381}} == "High") {  numericValue = 4;} else if ({{issue.customfield_10381}} == "Medium") {  numericValue = 3;} else if ({{issue.customfield_10381}} == "Low") {  numericValue = 2;} else if ({{issue.customfield_10381}} == "Very Low") {  numericValue = 1;} else {  numericValue = 0; // Or handle unexpected value as needed}// Convert 'Impact' to numericif ({{issue.customfield_10004}} == "Very High Impact") {  numericImpact = 5;} else if ({{issue.customfield_10004}} == "High Impact") {  numericImpact = 4;} else if ({{issue.customfield_10004}} == "Moderate Impact") {  numericImpact = 3;} else if ({{issue.customfield_10004}} == "Low Impact") {  numericImpact = 2;} else if ({{issue.customfield_10004}} == "Very Low Impact") {  numericImpact = 1;} else {  numericImpact = 0; // Or handle unexpected value as needed}// Convert 'Effort' to numericif ({{issue.customfield_10380}} == "Very Difficult") {  numericEffort = 5;} else if ({{issue.customfield_10380}} == "Difficult") {  numericEffort = 4;} else if ({{issue.customfield_10380}} == "Moderate") {  numericEffort = 3;} else if ({{issue.customfield_10380}} == "Easy") {  numericEffort = 2;} else if ({{issue.customfield_10380}} == "Very Easy") {  numericEffort = 1;} else {  numericEffort = 0; // Or handle unexpected value as needed}// Calculate 'Score Point'let scorePoint = (numericValue * 0.3) + (numericEffort * 0.2) + (numericImpact * 0.5);// Set the value of the 'Score Point' field{{issue.customfield_10424}} = scorePoint;
```

I don't know if I'm on the right way, as I'm not really into Jira scripting.

Any help is very welcome!

Thanks!


Answers:
author: Fernando Eug?nio da Silva
body: [@Gustavo Moraes](/t5/user/viewprofilepage/user-id/5285358)

Hey think this will be more easy to build and manage if you use Lookup Table Actions. With Lookup Table action you can say that for each priority value you have a specific number and then use some variable to keep the value and use for future math operations in your rule.

Here some useful links:

[New Automation action - Create lookup table - Atlassian Community](https://community.atlassian.com/t5/Automation-articles/New-Automation-action-Create-lookup-table/ba-p/2311333)

[Jira automation actions \| Cloud automation Cloud \| Atlassian Support](https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Create-lookup-table)

Also, I recommend read about math operations in Jira just to support you with your lookup tables: [Automation smart values - math expressions \| Cloud automation Cloud \| Atlassian Support](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/)

comments: author: Gustavo Moraes
body: Hi, [@Fernando Eug?nio da Silva](/t5/user/viewprofilepage/user-id/4606715) !  

I've re-created it with the Lookup Tables, but I'm failing hard on the script.

I've tried the formats below:

```
{
"fields": {
"customfield_10003": {{valueToUser(issue.fields.customfield_10381)}} * 0.3 + 
{{impactToCompany(issue.fields.customfield_10004)}} * 0.2 + 
{{effortToImplement(issue.fields.customfield_10380)}} * 0.5
}
}
```

```
{
"fields": {
"customfield_10003": 
{{#=}}({{valueToUser.get(customField_10381.asNumber.multiply(0.3))|0}} +
{{impactToCompany.get(customField_10004.asNumber.multiply(0.2))|0}} +
{{effortToImplement.get(customField_10380.asNumber.multiply(0.5))|0}})
{{/}}
}
}
}
```

```
?{
"fields": {
"customfield_10003": 
{{#=}}({{valueToUser.get(customField_10381.multiply(0.3))|0}} +
{{impactToCompany.get(customField_10004.multiply(0.2))|0}} +
{{effortToImplement.get(customField_10380.multiply(0.5))|0}})
{{/}}
}
}
}
```

And the list goes on...

I keep receiving the error:
> **(data was not an array (customfield_10003))**

Do you know how to handle it?

Thanks!


author: Gustavo Moraes
body: Also, I don't even know if this is the way to go.

Trying my best to learn it, lol.


author: Fernando Eug?nio da Silva
body: [@Gustavo Moraes](/t5/user/viewprofilepage/user-id/5285358) ,

I'll try to give you a highlight, assuming that you need to get values from different tables and apply a math operations.

First I created a table for priority field (I think you did this step perfectly). I'm using the default Priority field not a custom field.

Key = The value of the field

Value = The score associated for the choice

![Screenshot_187.png](https://community.atlassian.com/t5/image/serverpage/image-id/346686i3D54B1A565640407/image-size/large?v=v2&px=999 "Screenshot_187.png")

Then I've created a variable to Get the value from the table. Just created this variable:

![Screenshot_188.png](https://community.atlassian.com/t5/image/serverpage/image-id/346688iB4DB9C387E71B5EF/image-size/large?v=v2&px=999 "Screenshot_188.png")

At this point I have a table for Priority Field. Every time a Priority is selected, the table will get the current score for Priority using the variable: **PriorityScore**

---

I created a second table called CountryTable

![Screenshot_189.png](https://community.atlassian.com/t5/image/serverpage/image-id/346690i41EF111B0C63440A/image-size/large?v=v2&px=999 "Screenshot_189.png")

Same logic: Key is the choice selected and Value is the score for each choice. This Country field is a Custom Field. To get the associated score I created a variable for Country. I called this variable as **CountryScore**. Here your details:

![Screenshot_190.png](https://community.atlassian.com/t5/image/serverpage/image-id/346692iC871359FB74BCA28/image-size/large?v=v2&px=999 "Screenshot_190.png")

As you see, for custom select fields we need to pass: **issue.customfield_XXXX.value** for get the field reference in the table.

Now I have my score for Country saved in a var called **CountryScore**.

If I need to sum these both values, I just need to use this:

**{{#=}} {{PriorityScore}} + {{CountryScore}} {{/}}**

I'm applying a sum in Priority and Country score and the result should be the total of this sum.

If you need to multiply some one of these values, you can do something like this: **{{#=}} {{PriorityScore}} \* 2 + {{CountryScore}} {{/}}**

This operation math is my total. I guess if you follow this example adjusting for your field cases you'll able to build your math operations using lookup table.

Let us know any questions.

Fernando


author: Gustavo Moraes
body: Good morning, [@Fernando Eug?nio da Silva](/t5/user/viewprofilepage/user-id/4606715)

After struggling a lot and performing some tests with the {{#debug}} feature I managed to do it.

I've added the value and multiplied it by its weight already on the variable creation.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/346864i09CC147874DC00A6/image-size/large?v=v2&px=999 "image.png")

Then I just had to sum them, to have the final value.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/346866i999530A6BB1A0948/image-size/large?v=v2&px=999 "image.png")

Thank you SO MUCH for your patience and time, sir!


Tags: cloud

jira-service-management

jira-service-management-cloud