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 Leaders.
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

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 Leaders.
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 Leaders.
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 Leaders.
April 23, 2021

Should this work with JIRA?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events