Missed Team ’24? Catch up on announcements here.

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

How to get a user's email address in script runner (post function)'

Olivier Albertini October 20, 2014

I am trying to get the email address of reporter for JIRA HELP DESK 2.0

I have JIRA 6.3.6 and I use "Script runner"

Here my script :

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor

//IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
//Issue issue = issueManager.getIssueObject("ST-1799");

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField email = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Email"}
MutableIssue myIssue = issue
def reporterEmail = myIssue.getReporter().getEmailAddress()
myIssue.setCustomFieldValue(email, reporterEmail)

This script work only for user and not for "customer"

I think that "getEmailAddress()" comes from "crowd API" and customer is not in crowd but in JIRA DIRECTORY... 

 

Any workaround to fix this ?

Do you know other way to get Email address ?

 

Thank you very much.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Andreas Ebert
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.
October 20, 2014

User.getEmailAddress() should return the mail address for all kind of users, regardless if they come from Crowd or not. How exactly does that script not work? Do you get an error message? Is the "Email" custom field just not set?

Maybe the user really does not have a mail address set. Did you check that?

What do you mean with "customer"? Is that a special user?

Olivier Albertini October 21, 2014

Maybe the user really does not have a mail address set. Did you check that?

I did it

 Do you get an error message?

No

What do you mean with "customer"? Is that a special user?

I use JIRA HELP DESK 2.0 and It manage customer and agent, customer could not be an user (no licence), It's a restrited user. He cannot choose their prefered language (example)

 

The script work when I create an issue with a user but not for a customer who is not a user (he has no licence)

 

Andreas Ebert
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.
October 21, 2014

Ok, then customers are not JIRA users and therefore you cannot get the mail address like that. Sorry, I don't know how to do it for JIRA Service Desk 2.0.

Papyrum Nexus July 19, 2019

Hi, 

for anyone that reads this, probably you can get the customer email for another issue fields such as reporter por example, as customers are indeed created as clients of the project and most of the issues are created by them, always having in mind that they are registered users if not you can use a mandatory custom field when creating the issue to register email for public portals, so yo can access it an use it as needed.

For registered customers of the client portal, Test this sentences in the Scriptrunner console to display all issue structure: 

Note: obviously issuekey should be (def issueKey = "test-0001" --> your issue id)

def currentIssue = get('/rest/api/3/issue/' + issueKey)
.asObject(Map)

return currentIssue

Inside the body you will found the subdictionary "creator" where all information could be found.

Captura.JPG

Having this, you can now use any other Jira Api endpoint to keep going.

Hope it helps

 

Kind regards

Alberto Elvira Galindo - Papyrum

TAGS
AUG Leaders

Atlassian Community Events