Hi I have found a script that I want to make work in a Script Runner Custom field to display the full name not the username, which I then can use in the Jira macro in Confluence. My lack of groovy knowledge has me stuck on the 'token' error shown in snip .
Full script below:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.user.ApplicationUserCustomField field = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Owner")[0] // if there is no value for this field, exit the script if (!issue.getCustomFieldValue(field)) returnreturn (issue.getCustomFieldValue(field) as ApplicationUser).displayName
Thanks in advance
Cheers
Gordon
Hi Gordon
You see that error mainly due to a typo where your field declaration is on the same line as your import. Also, it appears there are a few other typos because you are missing some curly braces and the return statements are incorrect.
Finally, there is also the problem of trying to return a string (the display name) while using the `User Picker` script field Template, which expects you to return the ApplicationUser object.
If you want to return a string representing the user's `Display Name` you can use the `Text Field (multi-line)` script field template and a script like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def field = ComponentAccessor.customFieldManager.getCustomFieldObjects().find {
it.name == "Owner"
}
assert field
def value = issue.getCustomFieldValue(field)
// if there is no value for this field, return null
value ? (value as ApplicationUser).displayName : null
I hope this helps.
Regards
Matthew
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.