Forums

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

Set assignee using scriptrunner

Vishal
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.
April 23, 2021

Hello Guys,

For tasks issue types in one of my project I need to assign issues to one particular user, how could I achieve that using scriptrunner ?

I don't want to use workflow post function for procedural reasons in the organization, we need to set assignee as an initializer at the create screen itself, so that its visible to the users as well.

Please suggest if anything,

Tried this but not working.

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

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

Issue.setAssigneeId("userKey")

1 answer

0 votes
Radek Dostál
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.
April 23, 2021

I don't want to use workflow post function for procedural reasons in the organization, we need to set assignee as an initializer at the create screen itself, so that its visible to the users as well.

Well, you say you want an initializer (presumably using Behaviours - https://scriptrunner.adaptavist.com/6.20.0/jira/behaviours-overview.html), but what you're pasting is Java API which you would in fact use in a workflow post-function.

 

To change the field value on the create screen so that people see it before actually creating the issue, please see the above link to learn a bit about Behaviours. There are then also tutorials and some examples to get the first one set up.

 - basically need to create a behaviour and associate it with the project:issuetype mapping

 - add below as initializer / server-side script

 

Something like this should work:

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.*

//This makes it only run for the Create Issue action only
if (getAction()?.id == 1) {
def assigneeField = getFieldById(ASSIGNEE)
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("username") assigneeField.setFormValue(user.getKey())
}

 

Vishal
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.
April 26, 2021

Hello @Radek Dostál ,

I have tried this solution as well, at the create screen it shows me assignee set as JIRAUSERxxxxx but upon creation of issue, it is unassigned.

What should be the username ?, I have tried short id as well as full name of user but nothing working.

Thanks

Suggest an answer

Log in or Sign up to answer