Hi, you all
I will probably start biting into the table, as I have not reached the point of adding users from a user picker custom field to a user group using Scriptrunner, which is triggered by an automation rule.
import com.atlassian.jira.component.ComponentAccessor
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
final String groupName = "CSE_QM_InternalAuditor"
def group = ComponentAccessor.groupManager.getGroup(groupName)
final List<String> userToAdd = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("User"))
userToAdd.each {
def usertoaddhere = userManager.getUserByName(it)
if (!usertoaddhere) {
log.warn("User: $it doesn't exist")
return
}
if (ComponentAccessor.getGroupManager().getGroupsForUser(usertoaddhere).contains(group)) {
log.warn("User: $usertoaddhere.username already in the group: $groupName")
return
}
if(!group) {
log.warn("Group: $groupName doesn't exist")
} else {
userUtil.addUserToGroup(group, usertoaddhere)
log.warn("User: $usertoaddhere.username added to the $groupName")
}
}
I get the following error message:
Script function failed on Automation for Jira rule: AddUserToCSE_QM_InternalAuditor, file: <inline script>, error: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.user.util.DefaultUserManager.getUserByName() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser) values: [dobrkl(JIRAUSER23000)] Possible solutions: getUserByName(java.lang.String), getUserById(java.lang.Long), getUserByKey(java.lang.String), getUserState(com.atlassian.jira.user.ApplicationUser)
Does anybody have an idea why and how I can fix that?