Cannot Set Assignee of Sub-Task with ScriptRunner

Jh December 16, 2020

I have 15 post-function sub-tasks that all have almost the same exact format in which I set the assignee and additional assignee(custom field).

For this particular sub-task, I cannot get the sub-task to set the assignee correctly to the username I have, instead, once the sub-task is created, the Assignee is only set to the username text and not the actual agent and if I try to select from the Assignee drop-down list, it also just lists the username text from the script and I can no longer select their normal Jira full name from the drop-down list in the parent ticket and sub-tasks related. If I go to any other ticket and/or sub-task, I can select them normally as an Assignee. Once I unassign the original sub-task or assign to someone else, I can then also select the agent from the drop-down list normally. When looking at the ticket Activity, I noticed something strange, it sets the assignee to some generic Jira Username with numbers, screenshot attached.

Below is the script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

issue.setAssigneeId("User1")

issue.setDescription("--Remove user's name from telephone description\n--Change telephone owner to anonymous\n--Delete voicemail account\n--Delete extension from AD account")


 

Jira.png

 

1 answer

1 accepted

0 votes
Answer accepted
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 17, 2020

Hi @Jh ,

according to the documentation setAssigneeId expects to get userkey (not username). Your problem is probably related to the GDPR changes - new users have userkey like JIRAUSER10100 and it is not same as username anymore.

Jh December 17, 2020

@Hana Kučerová Hmm, interesting, that does seem like the case. The user is relatively new so that explains why. What is the solution? Do I use the userKey instead or is that randomized every time?

Jh December 17, 2020

nevermind, just tried using the userKey instead and it worked! Thank you!

Jh December 17, 2020

Going forward, how do I find the userKey of Jira users?

Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2020

Hi @Jh ,

you can get it using groovy script like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager

UserManager userManager = ComponentAccessor.getUserManager()
ApplicationUser user = userManager.getUserByName("username")
String userKey = user?.getKey()

Actually I don't know any easy way how to do it as a Jira administrator, so I asked myself here.

Jh January 9, 2021

@Hana Kučerová, I found out another kind of workaround to find out the userKey. I have a DEV project and just normally set the username in the Groovy script, I then create the ticket as normal with the groovyscript in the post-function workflow and after the ticket gets created with the invalid username I set the assignee or Unassigned or myself and I can see from the Jira activity what the userKey is.

Like Hana Kučerová likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13.1
TAGS
AUG Leaders

Atlassian Community Events