JIRA Builtin Script Listener - Create a sub-task. - How to set assignee?

I am using JIRA Builtin Script Listener - Create a sub-task. to create subtasks for Dev and QA for every story and bug in JIRA.

I would like the subtasks to be always assigned to user "Virtual QA". It seems that I have to do this through Additional issue actions field. I am trying to use:

issue.summary = ('QA: ' + issue.summary)
issue.assignee = 'Virtual QA'

This works only if I use only the first line to set the subtask summary but when I add the second line the script does not run. Can you please help me to solve it?

I was not able to help myself using the official documentation on:https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts

I have also tried solutions from https://answers.atlassian.com/questions/66562/set-assignee-to-some-specific-user-in-post-function-scriptAs Georgiy Senenkov Jul 03 '12 at 07:51 AM said, neither of the proposed solutions work. I tried all the described solutions and it did not work for me.

1 answer

1 accepted

0 votes
Henning Tietgens Community Champion Feb 04, 2014

You could not use a string of the user display name to set the assignee. You have to set the corresponding user object (com.atlassian.crowd.embedded.api.User) or you could use issue.assigneeId = 'userkey' (be aware that this is not the display name but the user key, which is the login name if you didn't renamed the user).

Thank you for your response. I am not able to find the userkey for the user, username does not work, mail which is used as login does not work and full name does not work to and I dont have direct access to database to verify.

How can I use the com.atlassian.crowd.embedded.api.User?

I need some line of code like issue.assigneeId = UserManager.findIdbyUsername("Virtual QA")

Henning Tietgens Community Champion Feb 05, 2014

Ok, here some code to give you a clue.

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserUtil

UserUtil userUtil = ComponentAccessor.getUserUtil()

// If you want a User object
User u = userUtil.getUser('username')

// If you need the key of a user (which don't change, so this could be done in the console and the key could be used in your scripts
ApplicationUser au = userUtil.getUserByName('username')
String key = au.getKey()

This works, thank you for the direction :)

import com.atlassian.jira.component.ComponentAccessor
issue.summary = ('QA: ' + issue.summary)
issue.setAssignee(ComponentAccessor.getUserUtil().getUser('qa'))

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,088 views 13 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot