assign issue to the user

Hi! 

There is a script, which takes values from the issue and creates a similar one with the same assignee, reporter, ect. Now we have a problem with users, which usernames were changed in Active Directory. There is a following error while creating: 

Assertion failed:
assert !validationResult.errorCollection.hasAnyErrors()
 
true

Errors: {assignee=User 'sam.st' does not exist.}

Error Messages: []

com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@66104f3
false

"sam" is the original username, but the current one is "sam.smith". 

I'm using getUserByKey() method to get an assignee and reporter values. 

So, what can I use to cover such a problem? Would the method getUserByName() reliable if the User Name is changed? Which column referrs to this method? 

The code looks like: 

def customFieldManager = ComponentAccessor.getCustomFieldManager()

    //current issue
	Issue issue  = issue
	def rep = issue.getReporterId() 
	def assign = issue.getAssigneeId()
 
//........ creating new issue 
			issueInputParameters.with 
  		  {
				// ..... 
			reporterId =  rep
            assigneeId = assign 
			// .....
		  }

Thanks in advance. 

6 answers

1 accepted

2 votes

So it seems:

issue.assigneeId

and:

issue.assignee.id

are two different things. The first returns the key and the second returns an actual id. Try using:

issue.assignee.name

It seems like setAssigneeId looks at the username, as you described.

0 vote
Vasiliy Zverev Community Champion Oct 06, 2016

Try to use setAssignee() method instead of setAssigneeId().

0 vote

The assignee and reporter id should be the user key. Are you sure this is whats breaking your script? It should continue working even when users have been renamed.

Hi Adam, 

Yes, I'm almost sure. We have several users with changed usernames and only for these ones the script returns error. 

Moreover, we have the following case: 

 

1st user renamed (from original -> to current) : sam    ---> sam.smith  

2nd user renamed (from original -> to current): sam.st ---> sam  

 

And, if Assignee (or reporter) is user with current username sam.smith , for new issue the assignee will be the user with username sam . If Reporter (or assignee) is user sam , the system returns me that user sam.st  doesnt exist. It looks like the getUserByKey takes the original (previous, user_key) value, and when parses it to the new issue, searchs between current usernames (lower_user_name). 

These users could be found in database, 

select * from app_user
where user_key <> lower_user_name

And for all these users the described problem exsists. 

Yes, I've tried to use issue.assignee.name and returned these values to the comment to see which value this method will return, seems that it works properly. 

Thank you! 

0 vote

Hi Saida, Glad you got it working. I have converted my comment to an answer. Would you be able to accept so other people get to see the solution too? Thanks.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

822 views 2 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you