I want to set custom field in scriptrunner mail handler. Works issueInputParameters.addCustomFieldValue(cf.id, '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 {it.name == 'My Custom Field'}
issueInputParameters.addCustomFieldValue(cf.id, 'My Values')
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,
Bob
Hi Bob,
Thanks for your answer.
Solved with this code,
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def TYtest = customFieldManager.getCustomFieldObjectByName("TYtest1")
issueObject.setCustomFieldValue(TYtest, addresses)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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) {
return
}
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.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Task" }.id)
issueObject.setReporter(reporter)
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Brian Keefe @Did you fixed the issue ? Same issue I am also facing
I am looking to set the value for single selection field which is having multiple issue context.
thanks,
om
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Brian Keefe I know, This is very old but it will help to someone else. I was searching the same after 2 yrs for the same. I couldn't find the answer so I had fixed this issue way back.
I am converting the created issue to mutable issue and then updating the custom field values for severity and request source type etc.
Here is the portion of the code .
issue = messageHandlerContext.createIssue(user, issueObject)
//creating the issue first with email reader using script runner
issue = messageHandlerContext.createIssue(user, issueObject)
//converting the created issue to mutableissue
MutableIssue mailissue = issue as MutableIssue;
//Getting the ID of relavenconfig for severity field.
def sevFld = customFieldManager.getCustomFieldObjectsByName("Severity").first()
def cfConfig = sevFld.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == '4-Low'
}
mailissue.setCustomFieldValue(sevFld, value)
issueManager.updateIssue(user, mailissue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.