从基于屏幕的API创建货件

时间:2018-04-23 10:44:29

标签: acumatica

我正在Acumatica中使用基于屏幕的Web服务调用创建货件。程序执行时没有错误并给出错误销售订单#不存在(即使它确实存在)。

程序一直持续到最后,有些订单会创建一个货件!如何仅检查此代码中包含的特定行?

  `              PSOrders.Current = psorderrec;
            if (psorderrec.Status == PSOrderStatus.Hold)
       {
            throw new PXException(String.Format(
                "Preshipment(0) is On Hold and cannot be generated.",
                psorderrec.PSOrderNbr));
        }
        else if (psorderrec.Status != PSOrderStatus.Open)
        {
            throw new PXException(String.Format(
                "Vendor {0} is already Processed.", psorderrec.PSOrderNbr));
        }



        so302000.Screen scr = new so302000.Screen();
        scr.CookieContainer = new System.Net.CookieContainer();
        so302000.LoginResult lr = scr.Login("USERNAME@COMPANYNAME:BRANCHNAME", "Password");
        if (lr != null && lr.Code == so302000.ErrorCode.OK)
        {

            so302000.Content schema = scr.GetSchema();

            var selectSOWithCommit = schema.Actions.SelectSO;
            selectSOWithCommit.Commit = true;

            var addSOWithCommit = schema.Actions.AddSO;
            addSOWithCommit.Commit = true;


            List<so302000.Command> commands = new List<so302000.Command>();

            commands.Add(schema.Actions.Insert);
            commands.Add(new so302000.Value
            {
                LinkedCommand = schema.ShipmentSummary.Customer,
                Value = psorderrec.CustomerCD
              });

            commands.Add(new so302000.Value
            {
                LinkedCommand = schema.ShipmentSummary.Location,
                Value = psorderrec.Location
            });

            commands.Add(new so302000.Value
            {
                LinkedCommand = schema.ShipmentSummary.WarehouseID,
                Value = psorderrec.Warehouse
            });

            commands.Add(new so302000.Value
            {
                LinkedCommand = schema.ShipmentSummary.NoteText,
                Value = psorderrec.PSOrderType+ "/" + psorderrec.PSOrderNbr
            });

            commands.Add(new so302000.Value
            {
                LinkedCommand = schema.ShipmentSummary.ControlQuantity,
                Value = psorderrec.ControlQty.ToString()
            });

            commands.Add(new so302000.Value
            {
                LinkedCommand = schema.ShipmentSummary.Operation,
                Value = "Issue"
            });


            commands.Add(new so302000.Value
            {
                Value = "OK",
                LinkedCommand =
                        schema.AddSalesOrderOperation.ServiceCommands.DialogAnswer,
                Commit = true
            });

            string pstype = psorderrec.PSOrderType;
            string psordernbr = psorderrec.PSOrderNbr;
            foreach (PSLine pslinerec in
            PXSelect<PSLine,
             Where<PSLine.pSOrderType, Equal<Required<PSLine.pSOrderType>>,
                            And<PSLine.pSOrderNbr, Equal<Required<PSLine.pSOrderNbr>>>>>.Select(this, pstype, psordernbr))
            {

                commands.Add(addSOWithCommit);
                commands.Add(new so302000.Value
                {
                    Value = pslinerec.SOOrderType,
                    LinkedCommand = schema.AddSalesOrderOperation.OrderType
                });
                commands.Add(new so302000.Value
                {
                    Value = pslinerec.SOOrderNbr,
                    LinkedCommand = schema.AddSalesOrderOperation.OrderNbr
                });
                commands.Add(new so302000.Value
                {
                    Value = "True",
                    LinkedCommand = schema.AddSalesOrder.Selected
                });
                commands.Add(schema.AddSalesOrder.InventoryID);
                commands.Add(schema.AddSalesOrder.Quantity);
                commands.Add(schema.AddSalesOrder.LineDescription);

                var soLines = scr.Submit(commands.ToArray());

// List commandList = new List();

               for (int index = 0; index < soLines.Length; index++)
                {
                    commands.Add(addSOWithCommit);
                    commands.Add(new so302000.Value
                    {
                        Value = index.ToString(),
                        LinkedCommand =
                           schema.AddSalesOrder.ServiceCommands.RowNumber
                    });
                    commands.Add(new so302000.Value
                    {
                        Value = "True",
                        LinkedCommand = schema.AddSalesOrder.Selected,
                        Commit = index < soLines.Length - 1
                    });
                }
            }

            commands.Add(schema.Actions.Save);

// commandList.Add(schema.Actions.Save);                 scr.Submit(commands.ToArray());                 scr.Logout();`

1 个答案:

答案 0 :(得分:0)

以下是使用基于屏幕的API创建货件的代码示例。

你的例子有点冗长 - 但我认为你也会看到与你的例子有些相似之处。此代码在登录后立即启动。

有一节添加SO,然后迭代SO中的每一行以更新值。

我希望这有帮助!

                var schema = shipScreen.GetSchema();
                var SelectSO = schema.Actions.SelectSO;
                SelectSO.Commit = true;
                var AddSO = schema.Actions.AddSO;
                AddSO.Commit = true;
                var Allocation = schema.Actions.LSSOShipLineBinLotSerial;
                Allocation.Commit = true;

                var commands = new Command[] {
                //first specify keys
                new Value { Value = "Shipment", LinkedCommand = schema.ShipmentSummary.Type },
                new Value { Value = OrderID.Trim(), LinkedCommand = schema.ShipmentSummary.ShipmentNbr }, 

                //header
                new Value { Value = CustID, LinkedCommand = schema.ShipmentSummary.Customer },
                new Value { Value = ShipName, LinkedCommand = schema.ShipmentSummary.Location },
                new Value { Value = SiteID, LinkedCommand = schema.ShipmentSummary.WarehouseID },
                new Value { Value = ShipDate.ToString(), LinkedCommand = schema.ShipmentSummary.ShipmentDate },
                new Value { Value = "False", LinkedCommand = schema.ShipmentSummary.Hold },

                //Add sales order
                new Value { Value = "OK", LinkedCommand = schema.AddSalesOrderOperation.ServiceCommands.DialogAnswer, Commit = true }, SelectSO,
                new Value { Value = OrderType, LinkedCommand = schema.AddSalesOrderOperation.OrderType }, // setting filter
                new Value { Value = OrderID, LinkedCommand = schema.AddSalesOrderOperation.OrderNbr }, schema.AddSalesOrder.InventoryID
                };

                var soLines = shipScreen.Submit(commands.ToArray()); // get list of SO lines
                List<Command> cmdList = new List<Command>();
                for (int i = 0; i < soLines.Length; i++) // select each line
                {
                    cmdList.Add(new Value { Value = i.ToString(), LinkedCommand = schema.AddSalesOrder.ServiceCommands.RowNumber });
                    cmdList.Add(new Value { Value = "True", LinkedCommand = schema.AddSalesOrder.Selected, Commit = true });
                }

                cmdList.Add(AddSO); //add selected lines to shipment
                shipScreen.Submit(cmdList.ToArray());

        //dt is the datatable with the fields that need to be entered - from the outside (non-acumatica) database
        //There is one row in dt for each line needed in the shipment.
                LineCounter = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    ProductID = dr.Field<string>("ProductID").Trim();
                    LotNumber = dr.Field<string>("LotNumber").Trim();
                    LineNum = dr.Field<int>("LineNumber").ToString();
                    LinePickQty = dr.Field<Int32>("PickQty").ToString();
                    SiteID = dr.Field<string>("SiteID").Trim();
                    LocationID = dr.Field<string>("LocationID").Trim();
                    UOM = dr.Field<string>("UOM").Trim();
                    LotPickQty = dr.Field<Int32>("LotQty").ToString();
                    if (LineCounter == 0)
                    {
                        cmdList.Clear();
                    }
                    cmdList.Add(new Key { Value = "='" + LineNum + "'", FieldName = schema.DocumentDetails.OrderLineNbr.FieldName, ObjectName = schema.DocumentDetails.OrderLineNbr.ObjectName });
                    cmdList.Add(new Value { Value = SiteID, LinkedCommand = schema.DocumentDetails.Warehouse });
                    cmdList.Add(new Value { Value = LocationID, LinkedCommand = schema.DocumentDetails.Location });
                    cmdList.Add(new Value { Value = UOM, LinkedCommand = schema.DocumentDetails.UOM });
                    cmdList.Add(new Value { Value = LinePickQty, LinkedCommand = schema.DocumentDetails.ShippedQty, Commit = true });
                    cmdList.Add(new Value { Value = LinePickQty, LinkedCommand = schema.Allocations.Quantity });
                    cmdList.Add(new Value { Value = "OK", LinkedCommand = schema.Allocations.ServiceCommands.DialogAnswer, Commit = true });
                    LineCounter = LineCounter + 1;
                }

                //Save
                cmdList.Add(schema.Actions.Save);
                cmdList.Add(schema.ShipmentSummary.ShipmentNbr);
                var shipment = shipScreen.Submit(cmdList.ToArray());