Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign tickets to the "correct" user using script runner in a post function

Navid Mohsenian August 17, 2018

Our Jira is integrated with our Active Directory. When our IT dept creates a new user in the Active Directory, the username (email) will be available in Jira.

When an Active Directory name is first created, Jira will make a record of it (lets call it username-contractor). My post functions works when I make issue assignments using one of these 2 functions:

issue.assigneeId = 'username-contractor'
Or issue.setAssigneeId("username-contractor")

But let's say the IT dept changes the user name at a later date to "username".

I can still use the functions as before and it works:

issue.assigneeId = 'username-contractor'
Or issue.setAssigneeId("username-contractor")

When in the ticket I hover over the assignee, I can see their new username and not the old username-contractor

Then I try to update my script and use the new username like below:

issue.assigneeId = 'username'
Or issue.setAssigneeId("username")

But when I do that It appears that I cannot use the same functions with the new username. As a result the ticket will not get assigned to the user.

So my question is, it is clear to me that Jira keeps 2 records of the user. What function can I use to set the assignee to the new username?

Appreciate any feedback.

 

 

1 answer

1 accepted

1 vote
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 17, 2018

Hello,

You would need to do it like this:

import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.getUserManager().getUserByName("username");
issue.setAssignee(user);

This post function must be first in the list of post functions and this post function must not be in the create issue transition.

Navid Mohsenian August 20, 2018

Thanks Alexey. Unfortunately although my post function is first in the list, I have my post function in the create issue transition. The reason is I am assigning tickets to particular users when they are first created. Is there a function that can be used in the create issue transition?

Navid Mohsenian August 20, 2018

Hi Alexey, after typing my reply I went ahead and implemented your solution in my create issue transition and it worked! I am using:

issue.setAssignee(ComponentAccessor.getUserManager().getUserByName("username"));

Thank you!

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2018

You are welcome! If my answer helped you , kindly mark my answer as accepted.

Suggest an answer

Log in or Sign up to answer