Hi,
I am getting a strange error when calling getCustomFieldValue() on a scripted field that has not been shown on a screen yet. I am running the following code in the Scriptrunner console:
<imports ad lib...>
void logCustomField(CustomFieldManager customFieldManager, Issue issue, String fieldName) {
CustomField[] customFields = customFieldManager.getCustomFieldObjectsByName(fieldName)
customFields.each{ CustomField customField ->
log.error(customField.getName() + " = " + issue.getCustomFieldValue(customField))
}
}
CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
IssueManager issueManager = ComponentAccessor.getIssueManager()
Issue issue = issueManager.getIssueObject("<some issue key>")
logCustomField(customFieldManager, issue, "Work Email") // Single line text field
logCustomField(customFieldManager, issue, "Resolver Group") // Single select drop-down
logCustomField(customFieldManager, issue, "Calculated Change Risk") // Calculated field
log.error("Done")
The output I get is:
2019-07-25 09:58:35,186 ERROR [runner.AbstractScriptRunner]: Work Email = email
2019-07-25 09:58:35,186 ERROR [runner.AbstractScriptRunner]: Resolver Group = null
By adding some more log statements I have pinpointed the problem to the getCustomFieldValue() call for the calculated field. And the code just stops. I have tried to enclose the call with a try-catch, the catch part is never reached.
But, the error only occurs if the calculated field has not been shown on a screen yet. If I view '<some issue key>' on a screen with the calculated field and try to run the code again, it works.
Using the preview function of scripted fields does not change anything - it still depends on the field having been shown on a screen.
I realise that it probably has something to do with the field not having been calculated and/or indexed yet. For my use case, it is okay that the return value is null or an exception is thrown - as long as my code is not exited.
And one final thing: When moving issues between projects in the GUI it seems that not all fields are listed - I cannot say for certain that it is the same problem but I have a bad feeling about this...
We are at Jira Core 8.1.0 / Scriptrunner 5.5.9.1-jira8
Best regards, Sune
A little update. Talked to Adaptivist support, they have now logged this a bug: https://productsupport.adaptavist.com/browse/SRJIRA-3741
I feel like it's not about field not being calculated/indexed, but about
customFieldManager.getCustomFieldObjectsByName("Calculated Change Risk")
not finding any field at all. are you sure field with this name exists?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ilya,
Thanks for the response.
The field does exist. I added the last line
log.error("Done")
To demonstrate that the script stopped while trying to print of information regarding the scripted field.
Also, I have changed the line logging the field value to:
log.error(customField.getName() + " = " + (customField.getCustomFieldType().getName() != "Scripted Field" ? issue.getCustomFieldValue(customField) : "<scripted field>"))
And I do get the expected output:
Calculated Change Risk = <scripted field>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.