Smart Send

Smart Send - Adding custom attachments

Return to main page
-->

Adding Custom Attachments

Overview

Smart Send uses the primary table and the email template to look for additional attachments, where document handling file type is specified against the business form in the parameters, and where the restriction of the file is set to External. Smart Send also includes an extension hook to enable a customer to create an extension class to attach a document handling attached file from another source, for example Purchase/Sales order lines. This technical guide provides sample code to achieve this for Purchase order lines.

Prerequisite

Minimum solution required is DXC Smart Business Form Email Manager Version 10.8.32.10030.

Add Purchase Order Line Attachments to PO Confirmation

Create an extension class for the ESSReport* class. Below is sample code on how to add purchase order line attachments to the email.

[ExtensionOf(classStr(ESSReportPurchPurchaseOrder))]
public final class ESSReportPurchPurchaseOrder_Extension
{
    public void additionalAttachment(SysOutgoingEmailTable _sysOutgoingEmailTable, ECL_AutoPrintReportMgmt _autoPrintReportMgmt)
    {
        next additionalAttachment(_sysOutgoingEmailTable, _autoPrintReportMgmt);
        if (_sysOutgoingEmailTable.ECL_RefTableId == tablenum(VendPurchOrderJour))
        {
            VendPurchOrderJour vendPurchOrderJour = VendPurchOrderJour::findRecId(_sysOutgoingEmailTable.ECL_RefRecId);
            
            if (vendPurchOrderJour)
            {
                PurchLine purchLine;
            
                while select purchLine
                    where purchLine.PurchId == vendPurchOrderJour.PurchId
                {
                    if (purchLine)
                    {
                        SysEmailTable::essCopyAttachmentToOutgoingEmail(_sysOutgoingEmailTable.EmailItemId, _autoPrintReportMgmt.DocuFileType, purchLine.TableId, purchLine.RecId);
                    }
                }
            }
        }
    }
}

Copy attachment method

Below is sample code on how to attach to an email.

    public static void essCopyAttachmentToOutgoingEmail(
        SysEmailItemId  _emailItemId, 
        DocuTypeId      _docuType, 
        TableId         _refTableId, 
        RefRecId        _refRecId)
    {
        DocuRef                 docuRef;        
        SysOutgoingEmailData    outgoingEmailData;
        Filename                attachmentFileExtension;

        select firstonly outgoingEmailData
            order by DataId desc
            where outgoingEmailData.EmailItemId == _emailItemId;
        SysEmailDataId dataId = outgoingEmailData.DataId;

        while select docuRef
        where docuRef.RefTableId  == _refTableId && docuRef.RefRecId    == _refRecId &&
              docuRef.TypeId       == _docuType &&
              docuRef.Restriction  == DocuRestriction::External
        {
            if (docuRef.isValueAttached())
            {
                dataId++;
                outgoingEmailData.EmailItemId   = _emailItemId;
                outgoingEmailData.DataId        = dataId;
                outgoingEmailData.EmailDataType = SysEmailDataType::Attachment;
                outgoingEmailData.Data          = docuRef.getFileContentAsContainer();
                outgoingEmailData.FileName      =  docuRef.docuValue().FileName;
                attachmentFileExtension = '.' + docuRef.docuValue().FileType;
                outgoingEmailData.FileExtension = attachmentFileExtension;
                outgoingEmailData.insert();
            }
        }
   }
© DXC Technology Company