Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

97 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you