Skip to main content

Would like to see a customization on attaching files to Purchase Orders and Purchase Order receipts automatically. When we enter receipts for our purchase orders, looking to see if there is a customization that will automatically match up the packing list with the receipts as well as, matching up the order confirmation with the Purchase order.

Automating the attachment of files (such as packing lists and order confirmations) to Purchase Orders and Purchase Order Receipts in Acumatica requires a customization that leverages the File Management API and hooks into the appropriate events during Purchase Order creation and receipt processing.

Here's a customization approach using C# in Acumatica to automatically attach documents to Purchase Orders and their associated Receipts.

Steps for Customization:

  1. Identify Key Documents to Attach:

    • Order Confirmation: Attach to the Purchase Order.
    • Packing List: Attach to the Purchase Order Receipt.
  2. Event Hooks:

    • Trigger automatic attachment upon PO Receipt entry.
    • Trigger automatic attachment when the Purchase Order is confirmed.
  3. Use the File Upload Mechanism: Acumatica's framework provides built-in file handling via PXNoteAttribute.AttachFile, which allows you to attach files to any document.

Step 1: Customization for Attaching Files to Purchase Orders

We will use a RowPersisted event to detect when a Purchase Order is created or confirmed, and attach the corresponding order confirmation file.

Code Example:

 

csharp

Copy code

using PX.Data; using PX.Objects.PO; using PX.SM; using System; namespace Customization { public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry> { protected void _(Events.RowPersisted<POOrder> e) { if (e.TranStatus == PXTranStatus.Open && e.Row.OrderType == POOrderType.RegularOrder) { // Check if this is the right event to trigger the attachment (e.g., Purchase Order confirmed) if (e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update) { // Attach the order confirmation file automatically AttachOrderConfirmation(e.Row); } } } private void AttachOrderConfirmation(POOrder order) { // Assuming the order confirmation file is already uploaded in the system Guid? fileId = GetFileIdByOrderConfirmation(order); // Implement logic to get the file ID (e.g., based on order number) if (fileId != null) { // Attach the file to the PO Order PXNoteAttribute.AttachFile(Base.Cachesstypeof(POOrder)], order, fileId); } } private Guid? GetFileIdByOrderConfirmation(POOrder order) { // Custom logic to get the order confirmation file's File ID based on order number // This could involve querying the SMFiles table to find a file associated with the order return null; // Replace with actual logic } } }

Step 2: Customization for Attaching Files to Purchase Order Receipts

The next step is to attach the Packing List when a Purchase Receipt is created. This can be done when the Purchase Receipt is inserted into the system, using the same file attachment mechanism as above.

Code Example:

 

csharp

Copy code

using PX.Data; using PX.Objects.PO; using PX.SM; using System; namespace Customization { public class POReceiptEntry_Extension : PXGraphExtension<POReceiptEntry> { protected void _(Events.RowPersisted<POReceipt> e) { if (e.TranStatus == PXTranStatus.Open && e.Row.ReceiptType == POReceiptType.POReceipt) { if (e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update) { // Attach the packing list automatically AttachPackingList(e.Row); } } } private void AttachPackingList(POReceipt receipt) { // Assuming the packing list file is already uploaded in the system Guid? fileId = GetFileIdByPackingList(receipt); // Implement logic to get the packing list file ID if (fileId != null) { // Attach the file to the PO Receipt PXNoteAttribute.AttachFile(Base.Cachesetypeof(POReceipt)], receipt, fileId); } } private Guid? GetFileIdByPackingList(POReceipt receipt) { // Custom logic to get the packing list file's File ID based on the receipt or purchase order number return null; // Replace with actual logic } } }

Step 3: Automate File Matching (Logic to Retrieve File)

For this customization, you’ll need to implement logic to retrieve the correct file based on the Purchase Order number or some other identifier. The file might already be uploaded by a user or an external integration (e.g., FTP, email import). You can query the SMFiles table or some external source to match files with the orders and receipts.

File Matching Function Example:

 

csharp

Copy code

private Guid? GetFileIdByOrderConfirmation(POOrder order) { // Query the SMFiles table or any related data to find the file by order number PXResultset<UploadFile> files = PXSelect<UploadFile, Where<UploadFile.name, Like<Required<UploadFile.name>>>>.Select(Base, "%" + order.OrderNbr + "%"); if (files.Count > 0) { UploadFile file = files.First(); return file.FileID; } return null; } private Guid? GetFileIdByPackingList(POReceipt receipt) { // Similar logic to match files for packing lists based on receipt data PXResultset<UploadFile> files = PXSelect<UploadFile, Where<UploadFile.name, Like<Required<UploadFile.name>>>>.Select(Base, "%" + receipt.ReceiptNbr + "%"); if (files.Count > 0) { UploadFile file = files.First(); return file.FileID; } return null; }

Step 4: File Storage and Retrieval

  1. File Upload: The files (e.g., order confirmations and packing lists) must be uploaded into Acumatica or made available through an integration with another system (e.g., FTP or email import).

    • Files in Acumatica are stored in the UploadFile table, and you can retrieve them by their FileID.
  2. File Naming Convention: If you are relying on automatic file matching, ensure the files are named in a way that makes them easy to search. For example, if the file names include the Purchase Order Number or Receipt Number, it simplifies file retrieval.

  3. Manual Upload Option: If a file isn't automatically found or uploaded, users can still manually attach the file using Acumatica’s built-in file attachment functionality.

Step 5: Testing and Refinement

Once the customization is complete:

  • Test the automation to ensure that files are being automatically attached when Purchase Orders are created and when Purchase Receipts are entered.
  • Verify that the correct files (packing list and order confirmation) are being matched and attached to the respective documents.

Additional Enhancements:

  • File Integration: Automate the uploading of packing lists and order confirmations from external systems (FTP, email, or other document management solutions).
  • User Notification: Notify users if no matching file is found when a Purchase Order or Receipt is processed.
  • Audit Trail: Maintain a log of all files automatically attached for better traceability.

Summary:

This customization leverages Acumatica’s file management system to automatically attach files (packing lists and order confirmations) to Purchase Orders and Purchase Receipts. It uses event handlers to detect when these documents are created or updated and retrieves the appropriate file from Acumatica’s file storage, attaching it automatically.


Reply