Search code examples
c#acumatica

Acumatica - Event When File is Attached to Document


I'm looking to run a method when a file is attached to a document in Acumatica (POOrder in this case). Essentially an event that is fired when a file is attached.

Through my research I was not able to find any documentation or similar questions that relate so I am unable to provide any code.


Solution

  • File upload within the Acumatica system is done through the UploadFileMaintenance graph. The data record that is referenced is UploadFile

    You can accomplish your goal of "run a method when a file is attached to a document in Acumatica" a variety of ways.

    You can add an event handler to UploadFileMaintenance via an extension as seen below

    public class UploadFileMaintenanceExtension : PXGraphExtension<UploadFileMaintenance>
    {
        public virtual void __(Events.RowInserting<UploadFile> e)
        {
        }
    
        public virtual void __(Events.RowInserted<UploadFile> e)
        {
        }
    }
    

    Actions can then be determined based on the files origination information ect.

    Inserting Information

    Similarly you can add an event for file saving specific to PO with the following

    public class POOrderEntryExtension : PXGraphExtension<POOrderEntry>
    {
        public override void Initialize()
        {
            PXGraph.InstanceCreated.AddHandler<UploadFileMaintenance>((graph) =>
            graph.RowInserting.AddHandler<UploadFile>((sender, e) =>
            {
                //Your code here
            }));
    
            base.Initialize();
        }
    }