Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with a script to work around jira issues macro to present full user names for user picker

Gordon Rutherford
Contributor
March 29, 2022

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).displayNametoken error.PNG

 

Thanks in advance

Cheers

Gordon

1 answer

1 vote
Matthew Clark
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 7, 2022

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

Suggest an answer

Log in or Sign up to answer