Hi Everyone,
Hope everyone is doing good. In our Organization we have around 6000 users per Jira Project and they have been assigned to 2 major roles irrespective of their actual role.
I am leading an initiative to create more roles in Jira and assign the existing 6000 users to their respective roles.
To my knowledge there is no way to perform this Automatically in Jira. So, Please help with the ways to change or an Script Runner script which can pick the user from the project and change to the new role.
Hi @Karthikeyan Devi ,
I created following script in order to solve your problem. Following script removes users from roleNameToRemove and add these users to roleNameToAdd:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.bc.projectroles.ProjectRoleService
def userManager = ComponentAccessor.userManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)
//Specify project and role
final def projectKey = '<PROJECT_KEY>'
final def roleNameToRemove = '<ROLE_NAME_TO_REMOVE_USERS>'
final def roleNameToAdd = '<ROLE_NAME_TO_ADD_USERS>'
final def actorType = 'atlassian-user-role-actor'
def project = ComponentAccessor.projectManager.getProjectByCurrentKey(projectKey)
def projectRoleToRemove = projectRoleManager.getProjectRole(roleNameToRemove)
def projectRoleToAdd = projectRoleManager.getProjectRole(roleNameToAdd)
def usernames = []
projectRoleService.getProjectRoleActors(projectRoleToRemove, project, null).roleActors.each {
usernames.add(it.parameter)
}
log.warn(usernames)
projectRoleService.removeActorsFromProjectRole(usernames as List<String>, projectRoleToRemove, project, actorType, null)
projectRoleService.addActorsToProjectRole(usernames as List<String>, projectRoleToAdd, project, actorType, null)
Please, just in case, try the code at a test project first.
And also, note that this script removes all users in the roleNameToRemove. You should modify the code if you need to remove specific users.
And finally, note that you can directly give a list of usernames to the last two functions if there are some specific set of users, for example:
def usernames = ["user1", "user2"]
Have a nice day!
Hi @Salih Tuç thanks for your effort, Let me try this script in my SIT Environment and Provide you the feedback. If any trouble will trouble you further more.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
below is my script,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, it seems like the first function is removing the content of usernames. so the second one fails.
Can you please try following for the last two lines:
projectRoleService.removeActorsFromProjectRole(usernames.clone() as List<String>, projectRoleToRemove, project, actorType, null)
log.warn(usernames)
projectRoleService.addActorsToProjectRole(usernames.clone() as List<String>, projectRoleToAdd, project, actorType, null)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is your Jira DC version?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.