Missed Team ’24? Catch up on announcements here.

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

Script Listener does not trigger sometimes on Issue Commented

ys October 27, 2022

We're trying to create a simple Helpdesk workflow with basic Jira (not Service Desk).

Our current setup uses the generic mail handler to "Create new issue or add comment", and we have a "Fast Track transition" listener act upon comments if current status == "To Do", the transition will move the ticket to another state

I noticed that if the email being sent contains only text, then the listener will work and the transition triggers properly. HOWEVER, if the email contains an attachment (or even small images within the email, 5~10kb in size), then the listener does not trigger at all.  That particular event does not even show up in the execution history of the listener, even though the comment created from the email appears in the ticket itself. 

Anyone know what could cause this? 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _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.
October 29, 2022

Hi @ys

Could you please share your code and Listener configuration so I can review it and provide some feedback?

Thank you and Kind regards,
Ram

ys October 31, 2022

Hi Ram,

Here's my listener configuration

image.png

Ram Kumar Aravindakshan _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.
November 3, 2022

Hi @ys

I have tried to replicate this issue in my environment, but I don't seem to be encountering the issue. I can transition the issue along with the attachments.

Below is a screenshot of my mail handler configuration:-

mail_handler_config1.png

Below is the sample code that I have tested with:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.util.JiraHome
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
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.mail.MailUtils
import org.apache.commons.io.FileUtils

def userManager = ComponentAccessor.userManager
def projectManager = ComponentAccessor.projectManager
def issueManager = ComponentAccessor.issueManager
def issueFactory = ComponentAccessor.issueFactory
def commentManager = ComponentAccessor.commentManager
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
def jiraHome = ComponentAccessor.getComponent(JiraHome)

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

if (issue) {
return
}

def user = userManager.getUserByName('admin')
def reporter1 = messageUserProcessor.getAuthorFromSender(message) ?: user
def project = projectManager.getProjectObjByKey('MOCK')

def issueObject = issueFactory.issue
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find { it.name == 'Bug' }.id)
issueObject.setReporter(reporter1)
issue = messageHandlerContext.createIssue(user, issueObject) as MutableIssue

def attachments = MailUtils.getAttachments(message)

def issueDescription = new StringBuilder(issue.description).append('\n')

attachments.each { it ->
def file = FileUtils.getFile(it.filename) as File
messageHandlerContext.createAttachment(file, it.filename, it.contentType, user, issue)
}

issue.setDescription(issueDescription.toString())
commentManager.create(issue, user, 'This is a sample', true)

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

log.warn '=======>>>> Mail Read <<<<======='

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

In my environment, I am not using any mail servers. So to test this, I have used the sample code above for this test case to read the *.eml file from the <JIRA_HOME>/import/mail folder. 

If you observe in the code, I have included:-

def commentManager = ComponentAccessor.commentManager
...
...
...
commentManager.create(issue, user, 'This is a sample', true)

So once the ticket is created, it will also include a comment, which will automatically cause the issue to transition to the Testing status.

For the Listener, I am using the same configuration that you have shared, i.e.:-

listener_configuration.png

Below are a few test screenshots for your reference:-

1. The email file is added to the <JIRA_HOME>/import/mail as shown below:-

mail_folder (1).png

2. Once the mail handler is executed, the mail folder is cleared, and the issue is created, as shown below.

issue_transitioned.png

If you observe, the issue is created with attachments and can transition to the Testing status without any issues.

I suggest you try to re-test this in your environment and ensure all your other plugins except for ScriptRunner are temporarily disabled before running the test.

Also, please note that I have run this test with the latest version of ScriptRunner, i.e. 7.4.0.

I hope this helps to solve your question. :-)

 

Thank you and Kind regards,

Ram

TAGS
AUG Leaders

Atlassian Community Events