Get email addrees from directory

Yonatan Leket August 16, 2018

I'm trying to create a new project consisting all employees information.

there is information that found in the directory , and I need it too.

I am trying to write a groovy script that will get the email of a user given the specified username (User picker custom_filed ) . 

But I don't know how to get the email that found in the user profile.

 

2018-08-16_0952.png2018-08-16_0950.png

2 answers

1 accepted

0 votes
Answer accepted
Mark Markov
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 16, 2018

Hello @Yonatan Leket

It should be like this

import com.atlassian.jira.component.ComponentAccessor

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Username").first()
def user = issue.getCustomFieldValue(customField)
def email = user.getEmailAddress()

 

Where you write your script? Is it postfunction or behaviour?

Yonatan Leket August 16, 2018

HI @Mark Markov,

I am trying to write a postfunction (scriptrunner Custom Script Field) , 

my goal is to get username's email after issue has been created,  

This filed will be shown in View issue screen .

in case you think is better to do it in behaviour just let me know .

Thanks!!

Mark Markov
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 16, 2018

If i ve got you right. You need a script field that will be display email of user in Username field?

If i do, go to script fields, create one, place on view screens and place this script in.

import com.atlassian.jira.component.ComponentAccessor

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Username").first()
def user = issue.getCustomFieldValue(customField)
def email = user.getEmailAddress()
return email
Yonatan Leket August 16, 2018

Yes, I need script field that will be display email of user in Username field.

Do you know what can be the reason for this Error? see attached 

2018-08-16_1417.png

Mark Markov
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 16, 2018

This is static type checking error. You can ignore it. This is happens because compiler doesnt know return type of getCustomField method. But in runtime it will work, just check!:)

0 votes
Yonatan Leket August 16, 2018

Indeed! all works as expected.

Tnx @Mark Markov!

Mark Markov
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 16, 2018

You re welcome! If it helps you, please mark my answer as accepted. So that, other people will be able to find this answer easily for similar questions :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events