You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I want to automatically assign a specific user (by using its username) based on the user group of the person creating the issue.
Therefore, I set up the following script by using Scriptrunner postfunction.
UserManager userManager = ComponentAccessor.getUserManager()
GroupManager groupManager = ComponentAccessor.getGroupManager()
def reporter = issue.getReporter()
if (groupManager.isUserInGroup(reporter, "AB01"))
else if (groupManager.isUserInGroup(reporter, "AB03"))
The purpose of this script is to assign the user "U123456" if the reporter is part of the user group "AB01" and to assign the user "U654321" if the reporter is part of the user group "AB03".
The users are well assigned to the issues in function of the user group but the problem is that they are not "recognized" as such in JIRA Service Desk although it's well their username. It acts as the assignee is empty even-though there is "U123456" or "U654321" in the field.
Did I do something wrong in my script ?
Thank you in advance for your help
Thank you for your question.
Can I please ask if you are using Jira Cloud or Jira Server as the code you have provided is not valid inside of Jira Cloud.
This means that it will not work inside of Jira Cloud, due to the fact the code you have provided is fro ScriptRunner for Jira Server. The reason for this that Atlassian only provide a rest API in Jira Cloud and do 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 you are using Jira Cloud the approach to use would be to be make a call to the Get user groups Rest API documented here in order to get all of the groups for the specified user.
You would then be able to use some logic to check if the user is in a group and would then be able to make a call to the Issue Rest API to update the issue and set the assignee. I can confirm that the code example here shows how to set the assignee when updating an issue.
You will be able to use these examples provided to create the script that you require to assign an issue based on a users groups inside of Jira Cloud.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Thank you for your response.
I would advise removing the Jira Cloud tag and tagging your question with the tag of com.onresolve.jira.groovy.groovyrunner so that users using the Server version can advise on how to achieve your requirement.
I would suggest that you try setting the user to be an ApplicationUser if it is not displaying correctly in Service Desk and can confirm that we have an example of how to do this here, but I am not sure if this could be the cause.