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,556,677
Community Members
 
Community Events
184
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
return
}

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 {
messageUserProcessor.findUserByEmail(it.address)
}

def issueObject = issueFactory.issue
def issueManager = ComponentAccessor.issueManager
def component = ComponentAccessor.projectComponentManager.findByComponentName(issue.projectObject.id, "COM1")
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find { it.name == defaultIssueType }.id)
issueObject.setReporter(reporterUser)
issue.setComponent([component])
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-------------

issue.setComponent([component])
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.

-sudheer

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
TAGS
AUG Leaders

Atlassian Community Events