Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How much program code is possible in Automation

ML
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 21, 2022

Hi,

Before I explain what I would like to achieve, here my question:

Is it possible to compute a field value in Jira automation to an extend I have in the following Groovy script?

I want to use Jira automation to calculate a value for a field, depending on two other fields which should be multiplied (Since the base fields hold the labels I first need to get the values scores)

Unfortunately the app, in which I need the value, does not support calculated custom fields. If the user edits the issue, updating any one of my to base fields I want to recalculate the depending field and set its value.

In the calucated field, if I could use it, I would use a Groovy script as follows to set the calculated field:


def significance = [Negligible:1, Moderate: 2, Significant: 3, Extensive:4, Catstrophic:5]
def probability = [Theoretical:1, Unlikely: 2, Possible: 3, Likely:4, Frequent:5]


Integer s = 0
Integer p = 0


//Evaluating the expression value
switch(issue.get("customfield_13418")) {

case "Negligible":
s = significance["Negligible"]
break
case "Moderate":
s = significance["Moderate"]
break
case "Significant":
s = significance["Significant"]
break
case "Extensive":
s = significance["Extensive"]
break
case "Catstrophic":
s = significance["Catstrophic"]
break
default:
s = 0
break;
}
switch(issue.get("customfield_13410")) {

case "Theoretical":
p = probability["Theoretical"]
break
case "Unlikely":
p = probability["Unlikely"]
break
case "Possible":
p = probability["Possible"]
break
case "Likely":
p = probability["Likely"]
break
case "Catstrophic":
p = probability["Frequent"]
break
default:
p = 0
break;
}

// return the value
s*p


Thanks for any idea!

3 answers

1 vote
Aron Gombas _Midori_
Community Champion
November 21, 2022

The out-of-the-box actions in Automation for Jira can't run Groovy scripts, but we developed an app called Better DevOps Automation which can.

This app has a general-purpose "Run Groovy" automation action which you can add to any automation rule, not just devops-minded ones.

For more information, see: https://midori-global.com/products/better-devops-automation-for-jira/server/documentation/automation-actions#run-groovy-script-action

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2022

Hi!

Please see the other answers regarding calling other code from a rule.

For your use case, I believe you can do this with the Jira Server version of Automation using a single statement, with conditions nested inside of a math operation.

For example:

{{#=}}( 0 + {{#if(equals(issue.significance.value, "Negligible"))}}1{{/}}{{#if(equals(issue.significance.value, "Moderate"))}}2{{/}}{{#if(equals(issue.significance.value, "Significant"))}}3{{/}}{{#if(equals(issue.significance.value, "Extensive"))}}4{{/}}{{#if(equals(issue.significance.value, "Catstrophic"))}}5{{/}} ) *( 0 + {{#if(equals(issue.probability.value, "Theoretical"))}}1{{/}} {{#if(equals(issue.probability.value, "Unlikely"))}}2{{/}} {{#if(equals(issue.probability.value, "Possible"))}}3{{/}} {{#if(equals(issue.probability.value, "Likely"))}}4{{/}} {{#if(equals(issue.probability.value, "Frequent"))}}5{{/}} ){{/}}

Please check your actual selection field values, as I copied from your posted question.

To learn more, please look at these references:

Kind regards,
Bill

0 votes
Florian Bonniec
Community Champion
November 21, 2022

Hi @ML 

 

Maybe you can do it without groovy script by doing an if then else for each combinaison. 

One other solution would be to store significance and probability in issue properties then calculate s*p

 

Regards

Suggest an answer

Log in or Sign up to answer