Display field according to the result of two other fields

Hi Team, I'm using script runner to get multiplication result of two fields in another fields (Riskrate)and to categorize the result in Riskrate to High,medium,low. For the same I have created the beklow script. But not completely functional. Please help 

def selecta= getFieldById("customfield_17796")
def selectb= getFieldById("customfield_23399")
def risk= getFieldById("customfield_28038")
def TestBed = getFieldById("customfield_26609")
long selectaVal = ((selecta.value ?: "0") as String).toLong()
long selectbVal = ((selectb.value ?: "0") as String).toLong()

risk.setFormValue(selectaVal * selectbVal)
long selectaValnew = ((selecta.value ?: "0") as String).toLong()
long selectbValnew = ((selectb.value ?: "0") as String).toLong()
long RiskrateVal = ((risk.value ?: "0") as String).toLong()

if(RiskrateVal <= 9)
{
if(RiskrateVal > 5)

{ TestBed.setFormValue("Medium") }

else

{ TestBed.setFormValue("Low") }

}
else

{ TestBed.setFormValue("High") }

@com.onresolve.jira.groovy.groovyrunner

7 answers

Hi,

What type are the custom fields customfield_28038, customfield_26609 ? I suppose the customfield_17796 and customfield_23399 are select lists (single choice) .

 

yes, these are select lists

and what about customfield_28038, customfield_26609 ?

customfield_17796 and customfield_23399 are select list and customfield_28038 is number field and customfield_26609 is a text field

Any update???

 

Hi,

Try adding the following code to a scripted field named "Risk Rate":

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue


Issue mainIssue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def impact = customFieldManager.getCustomFieldObjectByName("Impact")
def probability = customFieldManager.getCustomFieldObjectByName("Probability")
def impactVal = mainIssue.getCustomFieldValue(impact).toString().toInteger()
def probabilityVal = mainIssue.getCustomFieldValue(probability).toString().toInteger()
def overallRating = (impactVal * probabilityVal)
def result = ""

switch (overallRating) {
case { overallRating < 5}:
result = 'Low'
break
case {overallRating >= 5 && overallRating <= 9}:
result = 'Medium'
break
case {overallRating > 9}:
result = 'High'
break
default:
result = 'N/A'
break
}

return result;

You will have to change the names to match your field names and the case values to your preference. I have made the assumption here that the custom fields are text fields, so I casted them to string then to int. You will not need to do this is the field values are already numbers.

Also, if you would like both a risk rate numerical field and a text field then you will need to add a second scripted field and just return the 'overallRating' value instead of using the switch statement.

Take a look at this for more info on scripted fields: https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html

 

Hi, 

Did this solve your problem?

Regards,

Johnson Howard

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

239 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you