Hi Community,
We set up an email handler using ScriptRunner. The script was working fine, it was creating issues whenever an email was received. However, we added a custom drop-down field "Email Type" with multiple values. We would like to have the "Potential Spam" value selected whenever an issue is created by the mail handler. I added three lines to the script and try to make it works but it's not creating an issue when an email is received. When I remove these additional lines I added for the custom field then it works fine. Any idea what else needs to be added or removed in order to make it works?
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 org.apache.commons.io.FileUtils
def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def customFieldManager = ComponentAccessor.getCustomFieldManager() //added this line for custom field
def subject = message.getSubject() as String
def issue = ServiceUtils.findIssueObjectInString(subject)
if (issue) {
return
}
ApplicationUser user = userManager.getUserByName("security")
ApplicationUser reporter = messageUserProcessor.getAuthorFromSender(message) ?: user
def project = projectManager.getProjectObjByKey("NAS")
def issueObject = issueFactory.getIssue()
def emailType = customFieldManager.getFieldObjectByName("Email Type") //added this line for custom field
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Task" }.id)
issueObject.setCustomFieldValue(emailType, "Potential Spam") //added this line for custom field
issueObject.setReporter(reporter)
issue = messageHandlerContext.createIssue(user, issueObject)
Thank you,