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?