It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to set custom field in incoming mail handler in sciptrunner? Edited

I want to set custom field in scriptrunner mail handler. Works issueInputParameters.addCustomFieldValue(, 'my values') in transition post function. But, don't work in mail handler.

JIRA v7.12.1

ScriptRunner v5.5.7

Thanks for help.

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find { == 'My Custom Field'}
issueInputParameters.addCustomFieldValue(, 'My Values')


1 answer

Hi Nihat, 

using <issueobject>.setCustomFieldValue(<customfieldobject>,<value>) should work. 

Something like this ;

def issueObject = issueFactory.getIssue()
def cf = customFieldManager.getCustomFieldObject(12345)
issueObject.setCustomFieldValue(cf, "value")
messageHandlerContext.createIssue(user, issueObject)


Kind regards, 



Hi Bob,

Thanks for your answer.

Solved with this code,

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def TYtest = customFieldManager.getCustomFieldObjectByName("TYtest1")
issueObject.setCustomFieldValue(TYtest, addresses)

Hello - I'm trying to do this with a single select custom field. Glad to come across this, thanks for getting the thread started. But I still get a generic "Exception thrown while executing the script." error. Any ideas?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.service.util.ServiceUtils
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.mail.MailUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue

def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)

def subject = message.getSubject() as String
def issue = ServiceUtils.findIssueObjectInString(subject)

if (issue) {

ApplicationUser user = userManager.getUserByName("first.last")
ApplicationUser reporter = messageUserProcessor.getAuthorFromSender(message) ?: user
def project = projectManager.getProjectObjByKey("XYZ")

def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Country/Region")
def cfConfig = cfSelect.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == 'GB'

def issueObject = issueFactory.getIssue()
issueObject.setIssueTypeId(project.issueTypes.find { == "Task" }.id)
issueObject.setCustomFieldValue(cfSelect, value)

messageHandlerContext.createIssue(user, issueObject)

 I started with the example from ScriptRunner's documentation on Mail Handlers  + setting a select list + this thread. Thank you!

Hi Brian,

What is custom field type for "Country/Region"?

Single Select List - And it does have two different contexts, but if that's the blocker we could probably be okay with having the same values/options in the one field.

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you