Forums

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

Scriptrunner script to query field with username and set that to assignee

Deleted user August 29, 2019 edited

Fix denoted below. 

2 answers

2 accepted

0 votes
Answer accepted
Deleted user September 3, 2019 edited

I had resolved this with the following script: 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

def cField = customFieldManager.getCustomFieldObject("customfield_10077")
ApplicationUser user = issue.getCustomFieldValue(cField) as ApplicationUser
UserManager userManager = ComponentAccessor.getUserManager();
issue.setAssignee((user))


As a post function. 

0 votes
Answer accepted
PD Sheehan
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.
August 29, 2019

Will your custom field with user name be a User Picker or a Free Text field?

Either way, you should be able to just read that field's value with something like :

import com.atlassian.jira.component.ComponentAccessor
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName('Some Field with a user')
def user
if(cf.cusomtFieldType == 'com.atlassian.jira.plugin.system.customfieldtypes:userpicker'){
user = issue.getCustomFieldValue(cf)
} else {
def userName = issue.getCustomFieldValue(cf)
user = ComponentAccessor.userManager.getUserByName(userName)
}
issue.setAssignee(user)

I wouldn't actually write it this way -- with the "if".  You should already know which type your customer field is. But this should show you both ways to get a user object that can then be applied to the issue assignee field

And if you are doing this in a workflow post function, make sure that the script is before the "Update change history for an issue and store the issue in the database" step.

Deleted user September 3, 2019

Thank you for this!

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events