Forums

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

assign issue to the user

SaidAslan
Contributor
October 6, 2016

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
Answer accepted
adammarkham
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.
October 7, 2016

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 votes
adammarkham
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.
October 9, 2016

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.

0 votes
SaidAslan
Contributor
October 7, 2016

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 votes
SaidAslan
Contributor
October 7, 2016

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. 

0 votes
adammarkham
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.
October 7, 2016

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.

0 votes
Vasiliy Zverev
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.
October 6, 2016

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events