How to set the value of user picket custom field

Would like to set the value of a custom user picker filed in transition post function

1 answer

This widget could not be displayed.

You'll need an addon that provides such a post-function, or one of the scripting options like Script runner.

Once you've decided which route to take there, then we can probably help you (although it's "get user, put user in field" really)

Which addon would you recommend

Script runner. Always. (I'd have said that before either Jamie or I joined Atlassian, it's the one I've always turned to when something "clever" is needed)

I have Script Runner installed, I'm still new to Jira, could you provide sample code. I'm looking to set user picker custom field to a specific user.

Sorry Aron, missed the email update. I just rummage through Jamie's docs for examples - might be a good start though, as it's got custom field code and some stuff around users.

Was trying the script below and it does not work, following is the error from the log file.


java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.user.ApplicationUser
	at com.atlassian.jira.issue.customfields.impl.UserCFType.getDbValueFromObject(
	at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(
	at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(
	at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(
	at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(
	at com.atlassian.jira.issue.fields.OrderableField$ Source)
import org.apache.log4j.Category
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
log = Category.getInstance("com.onresolve.jira.groovy.CopyRegEx")
// Enter parameters here
// The example converts a reporter, which in my case has the format: Echlin, Jamie: DEPT (LOC), to Jamie Echlin - LOC.
def targetFieldName = "customfield_11103"
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField customFieldTarget = customFieldManager.getCustomFieldObject(targetFieldName)
def sourceVal = "mosheeh"
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
customFieldTarget.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customFieldTarget), sourceVal), changeHolder)

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

88 views 1 0
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