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

Scriptunner - Get user from userkey

Brian Michelsen June 8, 2023

I'm trying to figure out how to get a user when I only have the userkey, which I hope someone can help me with.

When mentioning someone on the page I can only get the userkey, and I need to figure out if some mentioned users are deactivated. I see that I have getUserByKey in the User Accessor, but that function needs a UserKey (

com.atlassian.sal.api.user.UserKey) as argument, which I cannot find out how to get.
Hope it makes sense, and hopefully someone can help out?

2 answers

1 accepted

3 votes
Answer accepted
Evgeniy
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.
June 8, 2023

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

UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor)


userAccessor.getUserByKey(new UserKey(userKey))

0 votes
Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2023

Hi Brian, your question seems to be unclear.  You are saying all you have is the userKey but then follow that by saying you cannot find out how to get the userKey.  Please clarify.

Brian Michelsen June 8, 2023

Yes maybe I'm not clear.

But as I was waiting I found out, that I just had to create a new UserKey object to use the String to obtain the actual UserKey.

UserKey userKey = new UserKey(<userkey as string>)

Like Craig Nodwell likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.19.8
TAGS
AUG Leaders

Atlassian Community Events