Determine custom field value based on 2 select lists

I have this requirement:

2 Select fileds:

Select field 1 (Impact) : Low Impact, Minor, Major, Unusable

Select field 2 (Probability) : Low, Medium, High, Crtical

Based on these selections another customer field (Severity) needs to be populated like Low/Low means Low, Unusable / Critical means High etc.

How can I achive this with script runner?

Appreciate your help (I am new to the scripting).


4 answers

1 accepted

There is a simpler ;-) example based on calculating a number based on some other issue fields here:

Hi Jamie,

I strated with calculating number example but it did not work. Here my example code

def Impact = getCustomFieldValue("Customer Impact")
def Probability = getCustomFieldValue("Customer Probability")
def Severity = "None"

if(Impact && Probability)
    if( (Impact == "No Impact") && (Probability == "Low") )
	Severity = "Low"

return Severity

Here Customer Impact & Customer Probability are select list and I selected return value as scripted field and "Free Text Field" for template.

Let me know what is wrong with it. It is always returning "None" here.

Also what is the easy way to debug these scripts (Any tools etc??).


There are several ways...

You could use a scripted field, read the values of the other fields and set the corresponding value. This is the easiest way.

If you want to use severity as a field within a statistic gadget, you have to write a listener which waits for changes to the other fields and sets the value of Severity accordingly. Severity has to be a select list (or an other type which is usable by statistc gadgets).

We use something like the following code to get something equal to your needs.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.event.type.EventTypeManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.FieldManager
import org.apache.log4j.Logger

import static com.atlassian.jira.event.type.EventType.ISSUE_DELETED_ID
import static com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH

 * This class is used to update custom field Anomaly with the corresponding
 * value with regard to Severity and Customer Value

class AnomalyClassWriter extends AbstractIssueEventListener {

    Logger log = Logger.getLogger(AnomalyClassWriter.class)
    IssueManager issueManager = ComponentAccessor.issueManager
    EventTypeManager eventTypeManager = ComponentAccessor.eventTypeManager
    FieldManager fieldManager = ComponentAccessor.getFieldManager()
    CustomFieldManager cfManager = ComponentAccessor.customFieldManager
    OptionsManager optionsManager = ComponentAccessor.getOptionsManager()

    // With customEvent() and workflowEvent() we get all events
    void customEvent(IssueEvent event) {
        // only one central way...

    void workflowEvent(IssueEvent event) {
        MutableIssue mIssue
        Map<Long,EventType> eventTypes = eventTypeManager.getEventTypesMap()

        if (event.eventTypeId != ISSUE_DELETED_ID && ['Bug', 'Request'].contains( {
            if (event.issue instanceof MutableIssue) {
                mIssue = (MutableIssue) event.issue
            } else {
                mIssue = issueManager.getIssueObject(
            updateAnomalyClassValue(mIssue, log)
        } else {

    void updateAnomalyClassValue (MutableIssue issue, Logger log) {

        def cfSeverity = cfManager.getCustomFieldObjects(issue).find { == 'Severity'}
        def cfCustomerValue = cfManager.getCustomFieldObjects(issue).find { == 'Customer Value'}
        def cfAnomalyClass = cfManager.getCustomFieldObjects(issue).find { == 'Anomaly Class'}

        String anomaly

        String severity = cfSeverity.getValue(issue)?.getValue()
        String customerValue = cfCustomerValue.getValue(issue)?.getValue()

        switch ([severity, customerValue]) {
            case {it == [ null, null]}:         anomaly = null; break;
            case {it == [ 'Low', null]}:
            case {it == [ 'Other', null]}:
            case {it == [ null, 'Low']}:
            case {it == [ 'Other', 'Low']}:
            case {it == [ 'Low','Low']}:        anomaly = '1'; break;
            case {it == [ 'Low', 'Medium']}:
            case {it == [ 'Other', 'Medium']}:
            case {it == [ null, 'Medium']}:
            case {it == [ 'Medium', 'Low']}:
            case {it == [ 'Medium', null]}:
            case {it == [ 'Medium', 'Medium']}: anomaly = '2'; break;
            default:                            anomaly = '3'

        def fieldConfig = cfAnomalyClass.getRelevantConfig(issue)
        def newOption = optionsManager.getOptions(fieldConfig)?.find{it.value == (anomaly)}
        issue.setCustomFieldValue(cfAnomalyClass, newOption)
        issueManager.updateIssue(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue, DO_NOT_DISPATCH, false)

This listener uses the value of the field Severity and Customer Value to calculate Anomaly for issue types "Bugs" and "Request". Maybe this is a good starting point for your script.


> If you want to use severity as a field within a statistic gadget

I think you can get round this problem by using Jozef's natural searchers:

Once I convert def to String it worked.

Thanks Henning for your nice Switch statement, which I used.

Can I ask what statements needed to be converted to string.


I converted the 3 field definitions to string so the values could be read out as string but when I run the script the resulting output is "class AnomalyClassWriter "



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


263 views 0 6
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