Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create User and Add to Group Edited

I am working on creating users more quickly, hoping someone could assist with helping me add the ability to create user and add to a specific group.

The creation script seems to be working (JIRA Server 8.5.x):

import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def userService = ComponentAccessor.getComponent(UserService)

UserService.CreateUserRequest createUserRequest = UserService.CreateUserRequest.
withUserDetails(user, "USERNAME", "ThisThis", "EMAIL ADDRESS", "First Last")
UserService.CreateUserValidationResult result = userService.validateCreateUser(createUserRequest)
if(result.isValid())
userService.createUser(result)
else
result.getErrorCollection()

 

I am trying to add where the created user with be added to a specified group. So far I have been running into issues where the variable is already in use. Any assistance is appertained. Thanks! 

2 answers

1 accepted

@Hi @Mike 

First of all, take care of the creation of users like that. If you use the password (wich is nullable) parameter in the method withUserDetails you wont let the user decide their passwords, and in my experience, they wont change their passwords at all.

If you don't care about it you should know that if you don't use 

createUserRequest.sendNotification(false)

they will receive an email notification in the creation.

With this said, lets go to the point, here you have the code to add the user to any group you want:

import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def userService = ComponentAccessor.getComponent(UserService)
def groupManager = ComponentAccessor.getGroupManager()
def group = groupManager.getGroup("MyGroup")

UserService.CreateUserRequest createUserRequest = UserService.CreateUserRequest.
withUserDetails(user, "USERNAME", "ThisThis", "EMAIL ADDRESS", "First Last")
UserService.CreateUserValidationResult result = userService.validateCreateUser(createUserRequest)
if (result.isValid()) {
def newUser = userService.createUser(result)
groupManager.addUserToGroup(newUser, group)
} else {
result.getErrorCollection()
}

Thank you

Can anyone help me with same issue on jira cloud? Thanks in advance 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Why everyone using Jira must be GDPR-compliant

Did you know that penalties up to 4 % of the yearly company turnover are possible in case of GDPR violations? GDPR regulations are currently mainly relevant for companies in the EU, but countries lik...

81 views 1 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you