Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,455,380
Community Members
 
Community Events
175
Community Groups

Using Scriptrunner postfunction to set assignee based on user group

Edited

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.

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.security.groups.GroupManager

import com.atlassian.jira.user.util.UserManager

UserManager userManager = ComponentAccessor.getUserManager()

GroupManager groupManager = ComponentAccessor.getGroupManager()

def reporter = issue.getReporter()

if (groupManager.isUserInGroup(reporter, "AB01"))

                {issue.setAssigneeId("U123456")}

else if (groupManager.isUserInGroup(reporter, "AB03"))

                {issue.setAssigneeId("U654321")}

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

1 answer

Hi Giles,

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.

Regards,
Kristian

Hi Kristian,

Thank you for your answer.

I'm using Jira Server. Indeed, I didn't mention that ...

Can you see where the mistake could be ?

Thank you in advance.

KR, 

Gilles

Hi Giles,

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.

Regards,
Kristian

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events