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.
- 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?
- 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?