Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner mailhandler script not working

Jason Li Ting Chung
Contributor
February 6, 2021

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

1 answer

0 votes
Hana Kučerová
Community Champion
February 6, 2021

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events