Solved

What's the difference between Document and CurrentDocument in SOOrderEntry?

  • 27 April 2022
  • 3 replies
  • 244 views

Userlevel 7
Badge +5

I’m working through a project and I’ve been looking up code examples here and there.

My question is: When do I use the primary view and when do I use the CurrentDocument view?

This SO answer shows the creation of a Sales Order and references CurrentDocument but the primary view of SOOrderEntry is Document:

SOOrder order = new SOOrder();
SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
order.OrderType = "SO";
order = graph.CurrentDocument.Insert(order);
order.CustomerID = project.CustomerID;
graph.CurrentDocument.Update(order);
graph.Actions.PressSave();

Whereas this SO answer shows the creation of a Purchase Order and references Document and POOrderEntry.cs has Document (primary view) and CurrentDocument (second view).

protected void createPO()
{
var graph = PXGraph.CreateInstance<POOrderEntry>();
var order = graph.Document.Insert(new POOrder());

order.OrderType = POOrderType.RegularOrder; // This is the default so not necessary
order.OrderDesc = "some text";
order.EmployeeID = 215;
order.Hold = false;
order.VendorID = 79;
graph.Document.Update(order);
graph.Actions.PressSave();

throw new PXRedirectRequiredException(graph, null);
}

My question is: When do I use the primary view and when do I use the CurrentDocument view?

 

icon

Best answer by Fernando Amadoz 27 April 2022, 19:06

View original

3 replies

Userlevel 5
Badge +2

@ddunn Typically, an Acumatica page that has information from the main DAC in both the header and any other containers - for instance a tab - manages 2 data views:

For the header:

public PXSelect<MainDAC> MainView

For the other container:

public PXSelect<MainDAC, Where<MainDAC.primaryKey, Equal<Current<MainDAC.primaryKey>>>> CurrentMainView

Both data views will store the same information. And you may use either of the 2 to get data.

However, I have encountered strange functionality when the “MainView” is defined in a second datamember, other than the main container’s.

My assumption is that the view from the main container manages the primary key information, and this is used internally by the framework for other purposes. Thus, when a second container also has this MainView datamember, it may lead to unexpected behavior.


1 - When creating new pages, or customizing an Acumatica page, I stick to the same methodology:
- one MainView for the main container, and
- one CurrentMainView for the other containers where it will be used.
Note: no need to define as many CurrentMainView views as alternative containers. You can use this one for all the rest.

 

2 - When utilizing the graph - for instance, instantiating the SOOrderEntry graph in order to create Sales Orders - I use the MainView for any data that may have to get inserted in the Main DAC.

No need to alternate between MainView and CurrentMainView while populating the logic regardless of where they are located in the page.

Badge +11

@Fernando Amadoz - I’m trying to throw on error on ShipVia, which is listed as being part of CurrentDocument, but nothing I do works. A field like OrderDesc works fine. Have you ever run into this?

Userlevel 5
Badge +2

@darylbowman Please create a separate post for your question.

Also, make sure to add code sample of what you have attempted.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved