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)
Hi Son,
I notice that you have marked this request as relating to ScriptRunner for Jira Cloud but I notice that your code is for ScriptRunner for Jira Server and will not work inside of Jira Cloud and this will not work as Atlassian only provides a rest API in Jira Cloud and does not provide a Java API in the cloud like they do in Jira Server.
You can see more detailed information on the differences between the cloud and server versions inside of our documentation page located here.
If your question relates to Jira Server then I would recommend re tagging this to specify Jira Server over Jira Cloud so that users familar with Jira Server see this question and can assist with it.
I hope this helps,
Regards,
Kristian
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.