Scriptrunner "failed to evaluate closure for adding attachment to email"

Daniel Garcia January 7, 2018

In my workflow postfunctions I have

  1. Set issue status to the linked status of the destination workflow step.
  2. Add a comment to an issue if one is entered during a transition.
  3. File Request.pdf will be created from template Account Access.docx in the pdf format and it will be attached to issue with name .
  4. File Request.docx will be created from template Account Access.docx in the docx format and it will be attached to issue with name .
  5. Update change history for an issue and store the issue in the database.
  6. Re-index an issue to keep indexes in sync with the database.
  7. Fire a Generic Event event that can be processed by the listeners.
  8. ScriptRunner workflow function - Send a custom email
    Send Request to Assigned Manager

postfunction 3 is an xporter plugin that creates the attachment "Request.pdf"
postfunction 8 is a canned "Send a custom email" scriptrunner script for sending emails. This script has the following custom attachment callback.

 

import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.MailAttachment

{MailAttachment a ->
    a.isNew() && a.filename.toLowerCase().endsWith('.pdf')
}

When I perform the transition I receive the email but without any attachments

In the log I see the following entry

[c.o.s.c.j.workflow.postfunctions.SendCustomEmail] Failed to evaluate closure for adding attachment to email
java.lang.NullPointerException: Cannot get property 'id' on null object
    at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:172)
    at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)

I found some code on pastebin for the canned script

 

class SendCustomEmailUniqueAttachment implements CannedScript{
.....

.....
private def addAttachmentsToMail(Map<String,String> params, MutableIssue issue, Email email) {
.....

.....
if (params[FIELD_INCLUDE_ATTACHMENTS] == FIELD_INCLUDE_ATTACHMENTS_CUSTOM) {
        def gse = CannedScriptRunner.getGse()

        try {
                def callback = gse.eval(params[FIELD_INCLUDE_ATTACHMENTS_CALLBACK])

                // todo: isNew method - see previous versions for ideas
                def mailAttachment = new MailAttachment(attachment)
                mailAttachment.setIsNew(newAttachmentIds.contains(attachment.id))
                def result = callback.call(mailAttachment)

                // Attachment.metaClass.
                log.debug "callback result for ${attachment.filename}: " + (result as Boolean)
                if (! result) {
                        return
                }
        } catch (e) {
                log.error("Failed to evaluate closure for adding attachment to email", e)
                return
        }
}

I assume is dying on the "mailAttachment.setIsNew(newAttachmentIds.contains(attachment.id))" line

Any ideas on how to work around this problem?

 

 

 

 

 

 

 

1 answer

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 9, 2018

I haven't come across that code before. At least that version of send custom email isn't in the latest versions of the product going back a few years.

Which version of ScriptRunner and Jira are you using?

Can you please post the fall stacktrace of the error you get? That should give us a line number it fails on.

The steps you've listed where you create the attachment and then send the email are all part of the same transition, correct?

Suggest an answer

Log in or Sign up to answer