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;
}
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}"
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.