Hello,
so I have a little script, which checks in the first if-condition, if the user is part of one group. If he is not, he will be created first, and added to the group (through "else). I thought, usually an if-condition will be ignored, if it is not true; but here my code keeps giving me an "Nullpointer Error" for the if-condition, and does not go to the else-condition.
import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def user = "newuser"
def groupNametoAddconfluence = "confluence-users"
def groupNametoAddjira = "jira-users"
def userToAdd = groupManager.getUserManager().getUserByName(user)
def groupNameToAdd = ComponentAccessor.getGroupManager().getGroup(groupName)
def usernotingroup = ['jira-users', 'confluence-users'].any {groupManager.isUserInGroup(user, it)}
if(!usernotingroup) {
ComponentAccessor.groupManager.addUserToGroup(groupNametoAddconfluence)
ComponentAccessor.groupManager.addUserToGroup(groupNametoAddjira)
} else {
ComponentAccessor.getUserUtil().createUserNoNotification(user, "", "Mail", "Full Name")
def groupName1 = ComponentAccessor.getGroupManager().getGroup(groupNametoAddconfluence)
def groupName2 = ComponentAccessor.getGroupManager().getGroup(groupNametoAddjira)
ComponentAccessor.groupManager.addUserToGroup(userToAdd,groupName1)
ComponentAccessor.groupManager.addUserToGroup(userToAdd,groupName2)