Is it possible for a customization project to receive an event when a file is attached to a record (project, invoice, etc.)?
The goal is to force a change to the LastModifiedDateTime of the project (for example) when a file is added so that the REST API will return the project when filtering by timestamp, since it seems that Acumatica doesn’t update the timestamp automatically when a file is added.
I have code that was generated with assistance from AI but I’m not sure if the approach is even valid. Should this RowInserted event for NoteDoc work and is the call to SetStatus() sufficient to update the LastModifiedDateTime value?
Trace information confirms that the extension is being loaded and a different event is received but not the event for NoteDoc.
public class ProjectEntry_Extension : PXGraphExtension<ProjectEntry>
{
public static bool IsActive() => true;
public ProjectEntry_Extension()
{
PXTrace.WriteInformation("ProjectEntry_Extension instance constructor invoked");
}
// Intercept when a file link (NoteDoc) is inserted
protected virtual void _(Events.RowInserted<NoteDoc> e)
{
PXTrace.WriteInformation("ProjectEntry_Extension: NoteDoc event received");
NoteDoc row = e.Row;
if (row == null) return;
// Fetch the current Project Header from PM301000's primary view
PMProject project = Base.Project.Current;
// Verify a project is loaded and matches the file's attached NoteID
if (project != null && row.NoteID == project.NoteID)
{
// Force an update to the project cache status
// This flags the record as "dirty" so the platform increments the tstamp
Base.Project.Cache.SetStatus(project, PXEntryStatus.Updated);
// Optional: Force an immediate database save.
// Remove the line below if you want the user to click 'Save' manually.
Base.Actions.PressSave();
}
}
}
