How To Imitate Click On Confirm Shipment In Acumatica
Hello everybody,
Today I want to describe how to imiate click on menu item "Confirm shipment" in Acumatica.
Probably your first guess will be just call method ConfirmShiment of graph SOShipmentEntry. But for now Acumatica team has another advice in order to call this action. Instead of calling method ConfirmShipment you'll need to have a bit more steps.
Code sample below demonstrates those necessary steps:
SOShipmentEntry shipmentGraph = PXGraph.CreateInstance<SOShipmentEntry>(); //Create instance of Graph
PXAutomation.CompleteSimple(shipmentGraph.Document.View); PXAdapter adapter2 = new PXAdapter(new DummyView(shipmentGraph, shipmentGraph.Document.View.BqlSelect, new List<object> { shipmentGraph.Document.Current })); adapter2.Menu = SOShipmentEntryActionsAttribute.Messages.ConfirmShipment; adapter2.Arguments = new Dictionary<string, object> { {"actionID", SOShipmentEntryActionsAttribute.ConfirmShipment} }; adapter2.Searches = new object[]{shipmentGraph.Document.Current.ShipmentNbr}; adapter2.SortColumns = new[] { "ShipmentNbr"}; soShipmentGraph.action.PressButton(adapter2); TimeSpan timespan; Exception ex; while (PXLongOperation.GetStatus(shipmentGraph.UID, out timespan, out ex) == PXLongRunStatus.InProcess) { }
//Here you'll have your shipment confirmed
And DummyView looks like this:
public class DummyView : PXView { List<object> _Records; internal DummyView(PXGraph graph, BqlCommand command, List<object> records) : base(graph, true, command) { _Records = records; } public override List<object> Select(object[] currents, object[] parameters, object[] searches, string[] sortcolumns,
bool[] descendings, PXFilterRow[] filters, ref int startRow, int maximumRows, ref int totalRows) { return _Records; } }
If you wonder, why calling ConfirmShipment is not enough, answer is this: ConfirmShipment cal will confirm shipment, but it will not execute Automation Steps. Thats why all of mentioned steps are needed. Otherwise, you'll make long research on question, why something doesn't work in the same way, as it works in UI, but doesn't work from my code.