AssigneeId not recognizing 20character length username

Kevin Lynch March 10, 2016

I've created a Script Runner Clone post function in my workflow. In the 'Additional issue actions' I have 'issue.assigneeId = "csramdocscoordinator"'

but when the ticket is created, it does not link to the user with this Id. instead it shows 'csramdocscoordinator#1' in the Assignee field.

How do I get it to recognize the Id correctly?

2 answers

1 accepted

2 votes
Answer accepted
crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 10, 2016

The "#1" comes from the automated rename of the userkey <=> username mapping that we hold onto for deleted accounts.  If you rename a user such that you reclaim a username that previously belonged to somebody else, the mapping for the old owner gets #1, #2, etc. added to it until we find one that gets it out of the way.  This is because we still keep the mapping for deleted users in case something is still referencing them and tries to look them up later.

The assigneeId is probably supposed to be the user's key, not the user's name, so you are setting it to the wrong account.  You can use UserKeyService.getKeyForUsername to find the correct value.

crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 10, 2016

As an example:

  1. Create user "alice" (her key is "alice")
  2. Create user "bob" (his key is "bob")
  3. Delete "alice"
  4. Rename "bob" to "alice".  Behind the scenes, this forces the old "alice" to be renamed to "alice#1", so we now have:
    key "alice" <=> username "alice#1"
    key "bob" <=> username "alice"
  5. Use "alice" in something that works with user keys

Now:

  • When you use "alice" is a username, you get the current "alice" who used to be "bob".
  • When you use "alice" as a user key, you get the old "alice" who got renamed to "alice#1".

To work with renamed users correctly, your code needs to use keys and usernames correctly.  You've used the wrong one, here.

Kevin Lynch March 10, 2016

According to  select * from cwd_user where user_name like '%sramdocscoordinator%' the only entry is the ID=53942 / USER_NAME=csramdocscoordinator

 

crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 10, 2016

A deleted user would not be in cwd_user anymore.  You would find the record in app_user.

Kevin Lynch March 14, 2016

Thanks, this worked. I looked in app_user for lower_user_name like '%sramdocscoordinator%' and found two User_Keys 'csramdocscoordinator' (the original) and 'sramdocscoordinator' (new value)

the 'csramdocscoordinator#1' that I was getting is tied to the csramdocscoordinator Id. So I used

issue.assigneeId = "sramdocscoordinator"

and the correct user is now in the tickets.

smile thanks

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.
March 11, 2016

Hi Kevin,

Using the issue.assigneeId method expects the ID of the user as a paramater and not the username of the user as described here.

What you should look to do is to get a new user object for the user and set this using the issue.assignee method as shown below.

import com.atlassian.jira.component.ComponentAccessor

// Get the User we want to set as the Assignee on the cloned issue
def user = ComponentAccessor.getCrowdService().getUser(("kwalker"))

// Set the Assignee based on the username and not by key.
issue.assignee = user

image2016-3-11 11:27:16.png

I hope this helps

Thanks

Kristian

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events