Hi community,
I have take a script for mailhandler from scriptrunner but it seems not to be working. When email are entering, it is commenting.
Here the code below, I have change the ProjectKey and IssueKey:
import com.atlassian.jira.component.ComponentAccessor
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
def userManager = ComponentAccessor.getComponent(UserManager)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def subject = message.getSubject() as String
def issue = ServiceUtils.findIssueObjectInString(subject)
if (issue) {
return
}
ApplicationUser user = userManager.getUserByName("Jason Chung")
ApplicationUser reporter = messageUserProcessor.getAuthorFromSender(message) ?: user
def project = projectManager.getProjectObjByKey("TE")
def issueObject = issueFactory.getIssue()
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find { it.name == "Service Request" }.id)
issueObject.setReporter(reporter)
messageHandlerContext.createIssue(user, issueObject)
Is there other changes that need to be done on the mailhandler itself or on the script?
Best regards,
Jason Li
Hi @Jason Li Ting Chung ,
I'm sorry, but it is not clear to me, what's wrong, what do you mean by "When email are entering, it is commenting." Do you get some sort of error message?
What is suspicious for me after checking your code:
ApplicationUser user = userManager.getUserByName("Jason Chung")
Is "Jason Chung" name of user? Because you need to provide username not name, so probably something like jason.chung. So, please check, that you get user object not null.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.