Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Getting the surname of a user from a User Picker custom field in script

PJ August 10, 2015

Hello,

I am trying to extract the surname of a user in a post-function script from a custom field (User picker). The goal is to use it to automatically populate another field.

The custom field is called Head of Department. I can get the username like this:

issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Head of Department"))

The problem is, first, it is only the username, and second, somehow it is doublely written. If a username is paulsmith, the value returned from the command above is paulsmith(paulsmith). I don't know why the same value is repeated in the (). Anyway, is there a way to get to the firstname or surname based on the value of this field?

Cheers

 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Tsol
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.
August 10, 2015

I think the following might work for you

issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Head of Department")).getName()
PJ August 10, 2015

Thanks a lot! It helped get rid of the extra (username) and now I have only the username without redundant repetition. Is there any way to get to the firstname or lastname based on this value? I know a class UserUtils, but I couldn't find proper documentation how to apply it in such a case.

PJ August 10, 2015

Thank you! Works like a charm! smile

Tsol
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.
August 10, 2015

Cool!. Please mark the answer as correct so that other users can easily find it.

1 vote
Tsol
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.
August 10, 2015

Try this one

issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Head of Department")).getDisplayName()
TAGS
AUG Leaders

Atlassian Community Events