how to get a user custom field email address through script runner ?


I set up a "send custom email script" post function via script runner and I would like to add the sender's email address in the signature of the email.

the sender refers to a user picker custom field. I created a scripted field to be able to get the email address to display it in the email.

In the scripted field, I wrote the following script :

import com.atlassian.jira.user.ApplicationUser

return issue.getEmailAddress("Change Request Owner Assignee")

I know something's missing but I did not manage to figure out the problem. i tried with String X= fieldX.getEmailAddress but in vain.

Any ideas?

Thanks a lot

2 answers

0 votes

getEmailAddress wants you to give it a user.  You appear to be feeding it a string which looks like the name of a field.

You need to do something more like getEmailAddress($issue.getCustomFieldValue(fieldManager.getCustomFieldByName("CR owner assignee")))

Although there's better ways to do it in a script, this at least shows you why your current code does not work.


Thanks for your answer.  I tryed your code but unfortunately it still does not work...



If you want them in the signature then what Nic said 

Email Addr: <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.customFieldManager.getCustomFieldObjectByName("CR owner assignee")) %>

Hi mel

In the "CC issue fields" field you can add the id of your user picker custom field, you can find it <baseUrl>/rest/api/2/field, it should be something like customfield_xxxx

(hit preview to make sure that it returns the emails). No need to copy the emails to scripted fields. 

Hi Thanos,

Thanks for your answer. yes I know that we can have the email cc but it's a "whim" I wanted to add in the email body like signatures in Outlook you know smile


Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

381 views 1 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot