Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,275
Community Members
 
Community Events
176
Community Groups

Setting Customer Request Type

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

2 answers

1 accepted

0 votes
Answer accepted

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, "######")

screen.png

 

Hello Ortakatman,

thanks for your help, but the code is not the solution. The customer request typ is still empty.

Kind regards
Jens

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events