Skip to main content
Solved

Issue with Attaching Files to Email Activity

  • 24 July 2024
  • 2 replies
  • 32 views

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



 

2 replies

Badge +12

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?

Badge +12

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