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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


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
Community Members
Community Events
Community Groups

How to update component while creating issue through scripted mail handler

Hello Community,

We have a requirement where components has to be updated while Issue created via mail handler.

Mail reached Mail_Q1 ---> Create Issue --> set the component as "Com1"  

Mail reached Mail_Q2 ---> Create Issue --> set the component as "Com2"  

Mail reached Mail_Q3 ---> Create Issue --> set the component as "Com3"  

So that we can differentiate Issues created from different mail queues. 

I have updated the script but getting error 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.exception.CreateException
import com.atlassian.jira.service.util.ServiceUtils
import com.atlassian.jira.service.util.handler.MessageHandlerContext
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 javax.mail.Message
import javax.mail.internet.InternetAddress

final targetProjectKey = 'TEST'
final defaultReporterName = 'admin'
final defaultIssueType = 'Task'

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

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

if (issue) {
// issue already exists so do nothing

def project = projectManager.getProjectObjByKey(targetProjectKey)

def user = userManager.getUserByName(defaultReporterName)
def reporterUser = messageUserProcessor.getAuthorFromSender(message) ?: user

def allCcRecipients = message.getRecipients(Message.RecipientType.CC) as List<InternetAddress>
def firstValidUser = allCcRecipients.findResult {

def issueObject = issueFactory.issue
def issueManager = ComponentAccessor.issueManager
def component = ComponentAccessor.projectComponentManager.findByComponentName(, "COM1")
issueObject.setIssueTypeId(project.issueTypes.find { == defaultIssueType }.id)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
firstValidUser ?
issueObject.setAssignee(firstValidUser as ApplicationUser) :
log.error('Unable to retrieve valid user from message CC list, issue will be created without assignee')

try {
(messageHandlerContext as MessageHandlerContext).createIssue(user, issueObject)
} catch (CreateException e) {
log.error('Error creating issue: ', e)

---error lines-------------

issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Can some help me to set the component also while creating an Issues through mail handler.


1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 11, 2022

Welcome to the Atlassian Community!

Ploughing through someone else's code is hard work.  It is clear what the intention is, but could you tell us what the error messages are and what line they are pointing to in your code?

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events