How to access ScriptRunner managed Scripted Fields?

Hello Everyone,

Is there any way to access the Scripted Fields inside ScriptRunner? In the field Rest API call (rest/api/2/field) custom fields do appear, however Scripted Fields don’t. The only workaround I have found is to write its output into a (simple) custom field (but since the Scripted Field must return with something its value is essentially in two different fields).

Thanks for your help in advance!

Hi Roland,

Thank you for your question.

I can confirm that Scripted Fields in Jira are not regular Jira fields as the value is stored against issue properties on an issue and the only way to extract their value is to make a call to the Issue Properties API in order to get the value for the field from the issue properties.

Can you please call the Issue Properties API in order to extract the values from the issue properties on the issue in order to return them inside of your script?

I can confirm that an example of how to call this API to get the value from a field that can be run on the Script console is included below for your reference.

def scriptedFieldName = "<ScriptedFieldNameHere>"
def issueKey = '<IssueKeyHere>'

def returnValue = ""

def scriptedFieldsForIssue = get("rest/api/2/issue/${issueKey}/properties")
        .header('Content-Type', 'application/json')
        .asObject(Map)
        .body
        .keys
        .findAll { it['key'].contains('scripted-field-')}['self']

if (scriptedFieldsForIssue == []) {
    return "No Scripted Field value exists yet on issue ${issueKey} with the name ${scriptedFieldName}."
}

scriptedFieldsForIssue.each {
    def potentialVal = get("${it}")
        .header('Content-Type', 'application/json')
        .asObject(Map)
        .body

    if (potentialVal.value.name == "${scriptedFieldName}") {
        returnValue = potentialVal.value.value
    }
}

return returnValue

I hope this information helps.

Regards,
Kristian

2 Likes

Hi Kristian,

Thank you very much for your answer and for providing the code.
It’s a perfect solution to my problem.

Regards,
Roland

2 Likes