Generate IN Receipt from the Code

Hi All,

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.

Acumatica Create Receipt

Code:

Have nice development!

1 Reply to “Generate IN Receipt from the Code”

  1. First of all thank you for this guide! There’s just one thing I would like to add: When I used your code and tried to persist a new INRegister the Exception “Document is out of balance.” was thrown. The reason for that is that the graph checks if the TotalQty and the ControlQty are equal. I fixed it by setting the ControlQty accordingly, but I think it’s also possible to disable this check in settings for IN.

Leave a Reply

Your email address will not be published. Required fields are marked *