Scripted Field - Need to return value but receive additional info

Cristy Flaherty
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!
February 21, 2025

Please bear with me - I am very new to groovy and haven't coded anything in years....

We have two custom dropdown fields (Technical Certainty and Definition Certainty), where users can select “High”, “Medium”, or “Low” :

When either of those values change, we want ScriptRunner to update a “Confidence Level” text field based on the combination of Technical and Definition Certainty. 

Regardless of the values, “Confidence Level” is set to “Undetermined”.  In the script, I returned the values of all three fields and found that it is returning more than just value for the Technical and Definition Certainty fields.  I'm not exactily sure what this is - is it from rest api?  I just want the value shown in bold.

 

The scripted field ran successfully.
"[self:https://******-sandbox.atlassian.net/rest/api/2/customFieldOption/10113, value:Medium, id:10113];
[self:https://******-sandbox.atlassian.net/rest/api/2/customFieldOption/10118, value:High, id:10118];
Undetermined"

Is there something I am missing to pull only the value?  Or is there something I need to do to convert or parse it?  Thoughts?

Thank you for your help!

Here is the script:

def issueKey = issue.key
def TCName = 'Technical Certainty'
def DCName = 'Definition Certainty'
def CLValue = 'Confidence Level'

def TCValue = Issues.getByKey(issueKey).getCustomFieldValue(TCName)
def DCValue = Issues.getByKey(issueKey).getCustomFieldValue(DCName)

def val = [TCValue, DCValue]

switch (val) {
    case {it == ['Low', 'Low']}:
        CLValue = '50%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    case {it == ['Low', 'Medium']}:
        CLValue = '60%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    case {it == ['Medium', 'Low']}:
        CLValue = '60%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    case {it == ['Low', 'High']}:
        CLValue = '70%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    case {it == ['High', 'Low']}:
        CLValue = '70%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    case {it == ['Medium', 'Medium']}:
        CLValue = '70%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    case {it == ['Medium', 'High']}:
        CLValue = '80%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    case {it == ['High', 'Medium']}:
        CLValue = '80%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    case {it == ['High', 'High']}:
        CLValue = '90%'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
    default:
        CLValue = 'Undetermined'
        "${TCValue}; ${DCValue}; ${CLValue}";
        break;
        }

 

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2025

Hi @Cristy Flaherty 

getCustomFieldValue returns more than just the value of the dropdown fields, it returns an JSON string including the id, value and the self calling URL. This is very expected behavior.

You need to modify your script to extract the wanted values.

Could you try the below code? (I've modified more as there were redundant lines)

I hope it helps

 

def issueKey = issue.key
def TCName = 'Technical Certainty'
def DCName = 'Definition Certainty'
def CLField = 'Confidence Level'

def TCValueObj = Issues.getByKey(issueKey).getCustomFieldValue(TCName)
def DCValueObj = Issues.getByKey(issueKey).getCustomFieldValue(DCName)

// Extract only the text values
def TCValue = TCValueObj?.value ?: "Undetermined"
def DCValue = DCValueObj?.value ?: "Undetermined"

// Default Confidence Level
def CLValue = 'Undetermined'

def val = [TCValue, DCValue]

switch (val) {
case ['Low', 'Low']:
CLValue = '50%'
break;
case ['Low', 'Medium'], ['Medium', 'Low']:
CLValue = '60%'
break;
case ['Low', 'High'], ['High', 'Low']:
CLValue = '70%'
break;
case ['Medium', 'Medium']:
CLValue = '70%'
break;
case ['Medium', 'High'], ['High', 'Medium']:
CLValue = '80%'
break;
case ['High', 'High']:
CLValue = '90%'
break;
}

return "${TCValue}; ${DCValue}; ${CLValue}"

 

0 votes
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2025

Hi,

welcome to the community

In cloud if you want to get the data from a field you need to call a rest api with scritprunner. Below some example from the scriptrunner doc. The first one should help you

https://docs.adaptavist.com/sr4jc/latest/features/scripted-fields/example-scripted-fields

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events