Sending Email From Custom Function With Attachment

Sending Email From Custom Function With Attachment

Hello,

I am trying to send an email from a custom task function within ServiceDesk 14.5 Build 14500 that contains an attachment retrieved from the /attachments/ endpoint. Here is my code as of now:
  1. configuration = global_configureAuth();
    requestObj = taskObj.get("request");
    attaches = [];
    for each attach in requestObj.get("attachments") {
        id = attach.get("id");
        res = invokeurl [
            url: "https://helpdesk.domain.com/api/v3/attachments/" + id
            type: GET
            headers: {"authToken": configuration.get("901").get("technicianKey"), "portalId": "901"}
        ];
        info res;
        attaches.insert(res);
    }

    sendmail
    [
        from: "***@domain.com"
        to: "***@domain.com"
        subject: "New Task Assigned - " + taskObj.get("title")
        message: "<div><h1>" + taskObj.get("title") + "</h1></div><div><table><tr><th>Employee Name</th><td>" + requestObj.get("udf_fields").get("udf_sline_100000606") + "</td></tr><tr><th>Start Date</th><td>" + requestObj.get("udf_fields").get("udf_date_100000611").get("display_value") + "</td></tr><tr><th>Department</th><td>" + requestObj.get("udf_fields").get("udf_pick_100000603") + "</td></tr><tr><th>Location</th><td>" + requestObj.get("udf_fields").get("udf_pick_100000602") + "</td></tr><tr><th>Job Title</th><td>" + requestObj.get("udf_fields").get("udf_sline_100000609") + "</td></tr></table></div><br /><div>Please see the attached documents for more information.</div><br /><div>When this task is completed, please reply to this email with 'Completed'.</div>"
        attachments:file:attach
    ];

    return {
        "status": "success",
        "message": "Successfully assigned task."
    };
The email is sent correctly, but I can't seem to get the email to send with the attachment specified, which should be any and all attachments added to the email. I also tried with an external test PNG file with the same result.

Please let me know if this capability exists within the Custom Functions module.

                  New to ADSelfService Plus?