How to update user programatically in jira plugin

Hi Experts,

I want to update user kindly refer me some sample code to update user like username and email address for user.

Note: I am using below code.

UserManager userManager = ComponentAccessor.getComponent(UserManager.class); 
ApplicationUser applicationUser= userManager.getUserByKey(employeeDTO.getUserKey()); 
userManager.updateUser(applicationUser);

Here how to set the values in application user as there is no setter method. Please can you guide me to update username and email in user.

1 Like

Hi,
you need to use UserService:

UserService userService = ComponentAccessor.getComponent(UserService.class);
ApplicationUser updateUser = userService.newUserBuilder(applicationUser).emailAddress("newEmail").name("newName").build();
UserService.UpdateUserValidationResult validationResult = userService.validateUpdateUser(updateUser);
if (validationResult.isValid()) {
    userService.updateUser(validationResult);
}
2 Likes

Thanks @driver ! :grinning: