Skip to main content
Solved

Issue with Attaching Files to Email Activity


CASE :   
Let's say we have attached a File on a Vendor.

Process: 
1. Create PO 
2. More Options > Click On Email Purchase Order
3. The File attached in the Vendor, should be displayed on the Email Activity Screen 

WHAT WE IMPLEMENTED :
you can refer to the code mentioned below 

ISSUE WITH THE CODE :
The implemented Code is that when we Create an Activity, it is not being attached on the first Time.
But when we Create an Email activity for the Second Time for the Same PO, it is  Attached.
We tried implementing Row Inserted, Row Persisted Events,  but the Event is not hitting when the email activity is Created. 

WHAT WE NEED HELP WITH :

To fetch the files attached to the vendor, in the First Go

 Code we Implemented: 
 

Image 01

 

Image 02



 

Best answer by darylbowman

Also, I understand your code is working (at some point), but there is a mechanism for uploading files that doesn’t involve a direct SQL insert. I’d highly recommend that.

This code looks up files attached to the Purchase Order and adds them to another screen:

var orderGraph = PXGraph.CreateInstance<POOrderEntry>();
POOrder order = orderGraph.Document.Search<POOrder.noteID>(row.RefNoteID);

var files = PXNoteAttribute.GetFileNotes(orderGraph.Document.Cache, order);
List<Guid> attachments = files.ToList();

foreach (Guid attachment in attachments)
{
    // Upload the files as attachments
    var uploadFileGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
    FileInfo fileInfo = uploadFileGraph.GetFile(attachment);
    uploadFileGraph.SaveFile(fileInfo, FileExistsAction.ReturnExisting);
    PXNoteAttribute.SetFileNotes(adapter.View.Cache, adapter.View.Cache.Current, fileInfo.UID.Value);
    uploadFileGraph.Persist();
    adapter.View.Graph.Persist();
}

 

View original
Did this topic help you find an answer to your question?

2 replies

darylbowman
Captain II
Forum|alt.badge.img+13

From having done this exact thing recently, I seem to recall that the Email action sends the email immediately. Have you tried executing your code BEFORE the baseMethod?


darylbowman
Captain II
Forum|alt.badge.img+13
  • 1608 replies
  • Answer
  • July 24, 2024

Also, I understand your code is working (at some point), but there is a mechanism for uploading files that doesn’t involve a direct SQL insert. I’d highly recommend that.

This code looks up files attached to the Purchase Order and adds them to another screen:

var orderGraph = PXGraph.CreateInstance<POOrderEntry>();
POOrder order = orderGraph.Document.Search<POOrder.noteID>(row.RefNoteID);

var files = PXNoteAttribute.GetFileNotes(orderGraph.Document.Cache, order);
List<Guid> attachments = files.ToList();

foreach (Guid attachment in attachments)
{
    // Upload the files as attachments
    var uploadFileGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
    FileInfo fileInfo = uploadFileGraph.GetFile(attachment);
    uploadFileGraph.SaveFile(fileInfo, FileExistsAction.ReturnExisting);
    PXNoteAttribute.SetFileNotes(adapter.View.Cache, adapter.View.Cache.Current, fileInfo.UID.Value);
    uploadFileGraph.Persist();
    adapter.View.Graph.Persist();
}

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings