Missed Team ’24? Catch up on announcements here.

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

Using Scriptrunner postfunction to set assignee based on user group

Gilles Vincent
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 6, 2019

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

Suggest an answer

Log in or Sign up to answer
0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 25, 2019

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

Gilles Vincent
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 25, 2019

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

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 26, 2019

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

TAGS
AUG Leaders

Atlassian Community Events