Question

Create a purchase order

  • 19 March 2024
  • 1 reply
  • 50 views

Userlevel 4
Badge +1

I’ve trying to create a simple purchase order but running into all types of problems. Can anyone explain why this isn’t working and offer a solution?

I’ve attempting to create a simple PO containing 1 inventory item. There are 2 methods below, both fail. 

  1. Setting properties directly. 
public POOrder CreateTransactionPO1(InventoryItem inventoryItem)
{
POOrderEntry graphPOOrderEntry = PXGraph.CreateInstance<POOrderEntry>();
POOrder pOOrder = (POOrder)graphPOOrderEntry.Document.Cache.CreateInstance();
pOOrder.OrderType = POOrderType.RegularOrder;
pOOrder = graphPOOrderEntry.Document.Insert(pOOrder);
pOOrder.VendorID = ((BAccount)Base.Select<BAccount>().FirstOrDefault(x => x.AcctCD == "ABB001")).BAccountID;
pOOrder = graphPOOrderEntry.Document.Update(pOOrder);

POLine pOLine = (POLine)graphPOOrderEntry.Transactions.Cache.CreateInstance();
pOLine.OrderType = POOrderType.RegularOrder;
pOLine = graphPOOrderEntry.Transactions.Insert(pOLine);
pOLine.InventoryID = inventoryItem.InventoryID;
pOLine = graphPOOrderEntry.Transactions.Update(pOLine);

pOLine.OrderQty = 1m;
pOLine = graphPOOrderEntry.Transactions.Update(pOLine);
pOLine.CuryUnitCost = 100m;
pOLine = graphPOOrderEntry.Transactions.Update(pOLine);

graphPOOrderEntry.Actions.PressSave();
graphPOOrderEntry.releaseFromHold.Press();
graphPOOrderEntry.markAsDontPrint.Press();
graphPOOrderEntry.markAsDontEmail.Press();

return pOOrder;
}

This code creates a purchase order BUT, the Line Type is Service which is incorrect, it should be ‘Goods for IN’; if I enter the same details in the UI the Line Type is set correctly. 

Can anyone explain why the Update command isn’t setting the LineType field based on the InventoryID?

  1. Setting values via the cache, using SetValueExt
public POOrder CreateTransactionPO(InventoryItem inventoryItem)
{
POOrderEntry graphPOOrderEntry = PXGraph.CreateInstance<POOrderEntry>();
POOrder pOOrder = (POOrder)graphPOOrderEntry.Document.Cache.CreateInstance();
pOOrder.OrderType = POOrderType.RegularOrder;
pOOrder = graphPOOrderEntry.Document.Insert(pOOrder);
Base.Caches<POOrder>().SetValueExt<POOrder.vendorID>(pOOrder, "ABB001");
pOOrder = graphPOOrderEntry.Document.Update(pOOrder);

POLine pOLine = (POLine)graphPOOrderEntry.Transactions.Cache.CreateInstance();
pOLine.OrderType = POOrderType.RegularOrder;
pOLine = graphPOOrderEntry.Transactions.Insert(pOLine);

Base.Caches<POLine>().SetValueExt<POLine.inventoryID>(pOLine, inventoryItem.InventoryCD);
pOLine = graphPOOrderEntry.Transactions.Update(pOLine);

Base.Caches<POLine>().SetValueExt<POLine.orderQty>(pOLine, 1m);
pOLine = graphPOOrderEntry.Transactions.Update(pOLine);
Base.Caches<POLine>().SetValueExt<POLine.curyUnitCost>(pOLine, 100m);
pOLine = graphPOOrderEntry.Transactions.Update(pOLine);

graphPOOrderEntry.Actions.PressSave();
graphPOOrderEntry.releaseFromHold.Press();
graphPOOrderEntry.markAsDontPrint.Press();
graphPOOrderEntry.markAsDontEmail.Press();

return pOOrder;
}

Using this method resolves the Line Type problem (using a breakpoint I can see that LineType=”GI”, but when PressSave() is called I get the error below. 

When entering a purchase order via the UI I don’t enter POAccrualType manually, so I expected that code above to set it for me. I don’t want to set the value myself as I’m not sure what it should be. Plus there could be other fields which need setting, don’t want to go down that route. 

What am I doing wrong?


1 reply

Badge +11

This works in demo data:

public class BusinessAccountMaint_Extension : PXGraphExtension<PX.Objects.CR.BusinessAccountMaint>
{
public PXAction<BAccount> ActionName;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "ActionName")]
public virtual void actionName()
{
var orderGraph = PXGraph.CreateInstance<POOrderEntry>();
POOrder order = orderGraph.Document.Current = orderGraph.Document.Insert();
orderGraph.Document.SetValueExt<POOrder.orderType>(order, POOrderType.RegularOrder);
orderGraph.Document.SetValueExt<POOrder.vendorID>(order, Base.BAccount.Current.BAccountID);
orderGraph.Document.Update(order);
POLine line = orderGraph.Transactions.Insert();
orderGraph.Transactions.SetValueExt<POLine.inventoryID>(line, 691);
orderGraph.Transactions.SetValueExt<POLine.orderQty>(line, 1m);
orderGraph.Transactions.SetValueExt<POLine.curyUnitCost>(line, 100m);
orderGraph.Transactions.Update(line);
//orderGraph.Actions.PressSave();

PXRedirectHelper.TryRedirect(orderGraph, PXRedirectHelper.WindowMode.New);
}
}

 

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