Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Convert Very High, High, Medium, etc. to number

Gustavo Moraes September 10, 2024

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

// Initialize numeric variables
let numericValue = 0;
let numericImpact = 0;
let numericEffort = 0;

// Convert 'Value' to numeric
if ({{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 numeric
if ({{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 numeric
if ({{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!

1 answer

1 accepted

2 votes
Answer accepted
Fernando Eugênio da Silva
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 10, 2024

@Gustavo Moraes 

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

Jira automation actions | Cloud automation Cloud | Atlassian Support

 

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

Gustavo Moraes September 10, 2024

Hi, @Fernando Eugênio da Silva !

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!

Gustavo Moraes September 10, 2024

Also, I don't even know if this is the way to go.

Trying my best to learn it, lol.

Fernando Eugênio da Silva
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 10, 2024

@Gustavo Moraes ,

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

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

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

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

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

Gustavo Moraes September 11, 2024

Good morning, @Fernando Eugênio da Silva

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

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

image.png

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events