Solved

Attaching files from Invoice and Memos screen to Email Activity screen

  • 8 March 2024
  • 5 replies
  • 97 views

Hey guys, 

 

I am currently developing a customization where I need to attach files from the Invoices and Memos screen to the Email Activity screen. E.g from this screen: 

to this screen: 

I am currently implementing the following logic: 

But it looks like the trace log below the assigning of the emailActivity retrieves a noteID of null although retrieving a file from the invoice:

 Any help on this would be greatly appreciated!

 

icon

Best answer by dewaldblaauw12 11 March 2024, 12:49

View original

5 replies

Badge +11

There may be a better way to do this, but this is what I would do:

public delegate IEnumerable SendEmailDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable SendEmail(PXAdapter adapter, SendEmailDelegate baseMethod)
{
var invoice = Base.Document.Current;

// Captures when the email graph is initialized
PXGraph.InstanceCreated.AddHandler<CREmailActivityMaint>((g) =>
{
// Captures when the email is inserted
g.RowInserting.AddHandler<CRSMEmail>((cache, e) =>
{
CRSMEmail row = (CRSMEmail)e.Row;
if (row == null) return;

var fileIDs = PXNoteAttribute.GetFileNotes(Base.Document.Cache, invoice);
foreach (Guid fileID in fileIDs)
{
PXTrace.WriteInformation($"{row?.NoteID}");
PXNoteAttribute.SetFileNotes(cache, row, fileID);
}
});
});

return baseMethod(adapter);
}

(ignore the weird code formatting)

I did try and implement your code. Still doesn’t seem to attach the files to the cr306015 screen :( 

Oky so I went ahead and debugged the process to see what the problem might be and gathered the following conclusion: 

It seems like the NoteID field is different in the Email Activity screen when the Send Email action is triggered. Here is the NoteID that is referenced by the Email Activity screen : 

(I created a datafield that retrieves the NoteID of this email)

 

Here is the NoteID that is retrieved in the customization’s code where the SendEmail action is overridden as mentioned in the main topic: 

What could cause the discrepancy ? 

Here is my Graph Extension code for the ARInvoiceEntry graph: 

 

I found a solution to the problem. Here is what I have done: 

I have extended the CREmailActivityMaint graph where the Email Activity screen’s buisness logic is. In this screen I have implemented the following code: 

In this RowInserted method the email activity is retrieved from CRSMEmail DAC, then the noteID is retrieved from this email activity. Afterwards the fileIDs are retrieved from the NoteDoc DAC for the respective noteID of the Invoice. Finally the fileIDs are stored in the cache of fileIDs of the EmailActivity in the “foreach” loop.

 

I hope this can help someone in the future!

Badge +11

@dewaldblaauw12 - If I’m reading this right, this will attach all files for any entity related to an email that is created. This could potentially cause a significant bloat to your database. I would suggest at least checking the type of the related entity.

 

Alternatively, did you try using a RowInserted event handler in my code? I can’t say what the difference would be. I usually use RowPersisting, but that won’t work in this case because the email isn’t being saved during the method.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved