The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

ScriptRunner for Confluence - get user name by email

Ramakrishnan Srinivasan
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 Champions.
April 17, 2020

Hi,

 I tried to get user name from email using ScriptRunner for Confluence. I tried the following code in scriptrunner console, 

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.user.UserAccessor

def userAccessor = ComponentLocator.getComponent(UserAccessor)
def users = userAccessor.getUsersByEmail("ramakrishnan.srinivasan@xyz.com")

users seems to be a class com.atlassian.crowd.embedded.atlassianuser.CrowdSearchResult

But I am not able to figure out how to parse this result to get the user name?

Can you please help me?

Thank you

With warm regards

ramki

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

2 votes
Answer accepted
Lasse Langhorn
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 Champions.
April 17, 2020

Hi Ramki,

 

You can do something like this:

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.user.UserAccessor

def userAccessor = ComponentLocator.getComponent(UserAccessor)
def users = userAccessor.getUsersByEmail("ramakrishnan.srinivasan@xyz.com")
if (users.pager().currentPage.size() == 1) {
return users.pager().currentPage.get(0).name
} else {
return "No single match"
}

Regards

Lasse Langhorn

Ramakrishnan Srinivasan
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 Champions.
April 17, 2020

Hi Lasse Langhorn,

Thank you, it worked for me. 

regards

ramki

David Harkins
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 Champions.
April 23, 2021

Should this work with JIRA?

TAGS
AUG Leaders

Atlassian Community Events