How to Copy and Paste Documents in Acumatica
Introduction
Copying and pasting documents in Acumatica is a common requirement during development, whether for creating duplicate records or initializing new ones based on existing data. Acumatica provides a flexible mechanism to accomplish this using the PXCopyPasteData class and caching functionalities. In this article, we'll explore how to implement this approach for a document and its related details grid, including handling cases where the [PXCopyPasteHiddenView] attribute is applied.
Understanding the Basics
In Acumatica, documents often consist of a primary record (e.g., ARInvoice) and associated child records stored in a details grid (e.g., ARTran). To copy these elements:
- Copy the document's primary record.
- Copy the associated grid records.
- Handle cases where specific views are excluded from the copy-paste functionality.
- Ensure proper cache handling and field updates for both primary and grid records.
About [PXCopyPasteHiddenView] Attribute
The [PXCopyPasteHiddenView] attribute is used to exclude a specific data view's cache from Acumatica's copy-paste feature. When applied to a view, the corresponding DAC's data is not automatically copied and pasted during operations.
Example Usage:
Implication for Development:
When this attribute is applied to a view in your source graph (e.g., Base.Transactions), you must explicitly loop through and copy the related records manually. This ensures the associated data is properly replicated in the new graph.
Key Points in the Code
- Handling [PXCopyPasteHiddenView]:
When a view is excluded using this attribute, looping through the details grid manually is necessary to replicate the data. - Grid Cache Initialization:
Ensure the cache for the details grid (ARTran) is properly initialized in the new graph. - Field Updates:
Assign new values to unique fields like NoteID to avoid conflicts. - Avoid Overriding Defaults:
Use PXCache<T>.RestoreCopy to replicate field values but ensure default system fields are preserved or updated appropriately.
Adapting for Other Document Types
This approach can be adapted for other document types in Acumatica. Replace ARInvoice and ARTran with the relevant DACs for your document and grid. Pay special attention to views with [PXCopyPasteHiddenView] or [PXCopyPasteHiddenFields] attributes and handle them explicitly in your implementation.
Conclusion
Copying and pasting documents in Acumatica is a powerful feature that, when implemented correctly, ensures efficiency and data consistency. By understanding the nuances of the [PXCopyPasteHiddenView] attribute and leveraging Acumatica's PXCopyPasteData class, you can handle even complex scenarios where certain views are excluded from automatic copying.
Feel free to adapt this example for your specific use cases. If you have questions or additional tips, drop a comment below!