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

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 vote

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

172 views 1 17
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you