In my experience I have quite a lot of questions like – how to create a document on the fly.
The answer is rather simple – we need to use the same objects as user interface and emulate user interface behavior.
- As the main object that contains a business logic and validation is Grpah, we need to create it from the code and use for calling actions and pushing data.
- INReceiptEntry graph = PXGraph.CreateInstance<INReceiptEntry>()
- To create a new object we can use PXCache.
- INRegister header = (INRegister)graph.CurrentDocument.Cache.CreateInstance();
- Every container control form UI is linked with Data View that is linked with DACs and tables. As you may know from Acumatica Platform Achitecture UI sends just 4 commends to the server logic (Insert, Update, Delete, Select). So in our code we need to use corresponding data views and call appropriate commands with data provided.
- header = graph.CurrentDocument.Insert(header);
- Acumatica uses Events triggered from UI we need to emulate it with calling appropriate commands of Data Views when necessary. For example if you choose Inventory Item, Acumatica defaults some values. We need to emulate this call to server logic with Update command.
- tran.InventoryID = 691; tran = graph.transactions.Update(tran);
- We also need follow the flow how user creates a record. For example we need to fill document first before entering transactions.
So basically that is it.
Please check my simple example extension where I create a Inventory Receipt from button on Sales Orders screen.
Have nice development!