Skip to main content
Answer

Is it possible to attach files from an AP Invoice to a notification email triggered by a business event? What is the best approach?

  • November 7, 2025
  • 1 reply
  • 42 views

I have a client that has setup a business event triggered by an ACH payment on an AP Invoice. The business event currently sends a notification email that contains an attachment generated by a report that contains the details of the AP Invoice.

The client ‘s request is to also attach any files that are attached to that AP Invoice to that same notification.

I have tried an approach where the business event would invoke a new action in APPaymentEntry that would compose the email from the email template with the attached report and then would get and attach any files attached to the APInvoice linked to the payment.

I have run into problems referencing the correct methods to generate the email notifications so the code would compile.

Is something like this possible? Is there another way I could hook into the standard Acumantica business event notification email process where I would not have to compose the email and attached report and just add the other attachments?

Thank you in advance for your input.

Best answer by Josiah Lisle

I have a client that has setup a business event triggered by an ACH payment on an AP Invoice. The business event currently sends a notification email that contains an attachment generated by a report that contains the details of the AP Invoice.

The client ‘s request is to also attach any files that are attached to that AP Invoice to that same notification.

I have tried an approach where the business event would invoke a new action in APPaymentEntry that would compose the email from the email template with the attached report and then would get and attach any files attached to the APInvoice linked to the payment.

I have run into problems referencing the correct methods to generate the email notifications so the code would compile.

Is something like this possible? Is there another way I could hook into the standard Acumantica business event notification email process where I would not have to compose the email and attached report and just add the other attachments?

Thank you in advance for your input.

Something like this should allow you to attach a copy of files from the document to the email:

 

Guid[] files = PXNoteAttribute.GetFileNotes(Base.Document.Cache, Base.Document.Current);

UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();
foreach (var note in files)
{
    PX.SM.FileInfo fi = upload.GetFile(note);

    PX.SM.FileInfo newFileInfo = new PX.SM.FileInfo(
        Guid.NewGuid(),
        null,
        fi.Name,
        fi.OriginalName,
        fi.Link,
        fi.BinData,
        fi.Comment
    );

    
    if (upload.SaveFile(newFileInfo, FileExistsAction.CreateVersion))
    {
        try
        {
            var noteDoc = new NoteDoc
            {
                FileID = newFileInfo.UID,
                NoteID = email.NoteID
            };
            emailActivityMaint.Caches[typeof(NoteDoc)].Insert(noteDoc);
            PXNoteAttribute.SetFileNotes(emailActivityMaint.Caches[typeof(CRSMEmail)], email, newFileInfo.UID.Value);
        }
        catch
        {
            throw new Exception("Failed to attach file to email.");
        }
    }
    else
    {
        throw new Exception("Failed to save file as a new version.");
    }
}

 

1 reply

Forum|alt.badge.img+1
  • Jr Varsity I
  • Answer
  • November 11, 2025

I have a client that has setup a business event triggered by an ACH payment on an AP Invoice. The business event currently sends a notification email that contains an attachment generated by a report that contains the details of the AP Invoice.

The client ‘s request is to also attach any files that are attached to that AP Invoice to that same notification.

I have tried an approach where the business event would invoke a new action in APPaymentEntry that would compose the email from the email template with the attached report and then would get and attach any files attached to the APInvoice linked to the payment.

I have run into problems referencing the correct methods to generate the email notifications so the code would compile.

Is something like this possible? Is there another way I could hook into the standard Acumantica business event notification email process where I would not have to compose the email and attached report and just add the other attachments?

Thank you in advance for your input.

Something like this should allow you to attach a copy of files from the document to the email:

 

Guid[] files = PXNoteAttribute.GetFileNotes(Base.Document.Cache, Base.Document.Current);

UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();
foreach (var note in files)
{
    PX.SM.FileInfo fi = upload.GetFile(note);

    PX.SM.FileInfo newFileInfo = new PX.SM.FileInfo(
        Guid.NewGuid(),
        null,
        fi.Name,
        fi.OriginalName,
        fi.Link,
        fi.BinData,
        fi.Comment
    );

    
    if (upload.SaveFile(newFileInfo, FileExistsAction.CreateVersion))
    {
        try
        {
            var noteDoc = new NoteDoc
            {
                FileID = newFileInfo.UID,
                NoteID = email.NoteID
            };
            emailActivityMaint.Caches[typeof(NoteDoc)].Insert(noteDoc);
            PXNoteAttribute.SetFileNotes(emailActivityMaint.Caches[typeof(CRSMEmail)], email, newFileInfo.UID.Value);
        }
        catch
        {
            throw new Exception("Failed to attach file to email.");
        }
    }
    else
    {
        throw new Exception("Failed to save file as a new version.");
    }
}