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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for this!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.