Forums

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

How to add multiple user is this script

Vikrant Yadav
Community Champion
May 4, 2020

Hi @Ravi Sagar _Sparxsys_  please suggest, how can i add more user in below script,this script is for single user :-

https://library.adaptavist.com/entity/create-a-user-in-jira

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

// the username of the new user - needs to be lowercase and unique - required
final String userName = "user"

// The password for the new user - if empty a random password will be generated
final String password = "password"

// The email address for the new user - required
final String emailAddress = "user@jira.com"

// The display name for the new user - required
final String displayName = "New User"

// notifications are sent by default, set to false to not send a notification
final boolean sendNotification = false

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def userService = ComponentAccessor.getComponent(UserService)

def newCreateRequest = UserService.CreateUserRequest.withUserDetails(loggedInUser, userName, password, emailAddress, displayName)
.sendNotification(sendNotification)

def createValidationResult = userService.validateCreateUser(newCreateRequest)
assert createValidationResult.isValid() : createValidationResult.errorCollection

userService.createUser(createValidationResult)

Thanks

VIkrant Yadav

 

1 answer

0 votes
Ravi Sagar _Sparxsys_
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.
May 4, 2020

Hi @Vikrant Yadav 

Create a method (function) with the code above and call it for each user.

Now you can create a csv with a list of users and use the above code to create multiple users based on entries in the csv file. I shared code to read csv file to create multiple users. 

I hope it helps.

Ravi

Vikrant Yadav
Community Champion
May 4, 2020

HI @Ravi Sagar _Sparxsys_  for this i need to paste file on JIRA server. JIRA server is not accessible by me. Any alternate script to add multiple user. Please suggest

 

thanks

Ravi Sagar _Sparxsys_
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.
May 5, 2020

Where is your list of users then? and in what format?

Suggest an answer

Log in or Sign up to answer