You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello, i want to set the cutomer request type of an issue which is created by mail.
I use this code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.util.JiraHome
import com.atlassian.jira.service.services.file.FileService
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)
JiraHome jiraHome = ComponentAccessor.getComponent(JiraHome)
def subject = message.getSubject() as String
def issue = ServiceUtils.findIssueObjectInString(subject)
if (issue) {
return
}
ApplicationUser user = userManager.getUserByName("admin")
ApplicationUser reporter = messageUserProcessor.getAuthorFromSender(message) ?: user
def project = projectManager.getProjectObjByKey("#####")
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def issueObject = issueFactory.getIssue()
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Softwareprobleme" }.id)
issueObject.setReporter(user)
issue = messageHandlerContext.createIssue(user, issueObject)
def attachments = MailUtils.getAttachments(message)
attachments.each { MailUtils.Attachment attachment ->
def destination = new File(jiraHome.home, FileService.MAIL_DIR).getCanonicalFile()
def file = FileUtils.getFile(destination, attachment.filename) as File
FileUtils.writeByteArrayToFile(file, attachment.contents)
messageHandlerContext.createAttachment(file, attachment.filename, attachment.contentType, user, issue)
}
def crtField = customFieldManager.getCustomFieldObjects(issue).find{it.name == "Customer Request Type"}
issue.setCustomFieldValue(crtField, "#####/######")
But the customer request type is not set. What have i made wrong?
Kind regards
Jens
I have find a solution.
with this code i solve the problem:
crtField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def requestType = crtField.getCustomFieldType().getSingularObjectFromString("###/#####")
issue.setCustomFieldValue(crtField, requestType)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Hi Jens,
Can you try.
def crtField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
issueObject.setCustomFieldValue(crtField, "######")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ortakatman,
thanks for your help, but the code is not the solution. The customer request typ is still empty.
Kind regards
Jens
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.