得到"类型可能不是空的"尝试添加"折扣详情"时出错在通过Web API的销售订单中

时间:2015-09-02 15:04:52

标签: acumatica

我尝试使用以下代码通过网络API添加带预设折扣代码的销售订单:

        SO301000Content SO301000 = context.SO301000GetSchema();
        context.SO301000Clear();

        List<Command> cmds = new List<Command>();


        cmds.Add(new Value { Value = "SO", LinkedCommand = SO301000.OrderSummary.OrderType });
        cmds.Add(new Value { Value = "<NEW>", LinkedCommand = SO301000.OrderSummary.OrderNbr });
        cmds.Add(new Value { Value = orderInfo.OrderCustomerInfo.AcctCD, LinkedCommand = SO301000.OrderSummary.Customer });
        cmds.Add(new Value { Value = orderInfo.OrderLocationInfo.ID, LinkedCommand = SO301000.OrderSummary.Location });

        cmds.Add(new Value { Value = orderInfo.ShippingTotal.ToString(), LinkedCommand = SO301000.Totals.PremiumFreight });

        cmds.Add(new Value { Value = "N30", LinkedCommand = SO301000.FinancialSettingsFinancialInformation.Terms});


        cmds.Add(new Value { Value = orderInfo.OrderNumber, LinkedCommand = SO301000.OrderSummary.ExternalReference });

        if (orderInfo.ShippingTotal > 0) { 
            cmds.Add(new Value { Value = orderInfo.ShippingTotal.ToString(), LinkedCommand = SO301000.Totals.PremiumFreight });
            cmds.Add(new Value { Value = orderInfo.ShippingTaxCategory, LinkedCommand = SO301000.Totals.FreightTaxCategory });
        }

        if (!string.IsNullOrEmpty(orderInfo.PromoCode))
        {
            cmds.Add(SO301000.DiscountDetails.ServiceCommands.NewRow);
            cmds.Add(new Value { Value = orderInfo.PromoCode, LinkedCommand = SO301000.DiscountDetails.DiscountCode });
            cmds.Add(new Value { Value = "000", LinkedCommand = SO301000.DiscountDetails.SequenceID });
            cmds.Add(new Value { Value = "Group", LinkedCommand = SO301000.DiscountDetails.Type });
            cmds.Add(new Value { Value = orderInfo.OrderQty.ToString(), LinkedCommand = SO301000.DiscountDetails.DiscountableQty });
        }



        //add line items
        foreach (OrderItem item in orderInfo.OrderItems)
        {
            cmds.Add(SO301000.DocumentDetails.ServiceCommands.NewRow);
            cmds.Add(new Value { Value = item.InventoryCD, LinkedCommand = SO301000.DocumentDetails.InventoryID });
            cmds.Add(new Value { Value = item.Quantity.ToString(), LinkedCommand = SO301000.DocumentDetails.Quantity });
            cmds.Add(new Value { Value = "Server", LinkedCommand = SO301000.DocumentDetails.Warehouse });


            cmds.Add(new Value { Value = "True", LinkedCommand = SO301000.DocumentDetails.ManualDiscount});

            if (item.DiscountPercent > 0)
            {
                cmds.Add(new Value { Value = item.DiscountPercent.ToString(), LinkedCommand = SO301000.DocumentDetails.DiscountPercent, Commit = true });
            }
            else if (item.DiscountAmount > 0)
            {
                cmds.Add(new Value { Value = item.DiscountAmount.ToString(), LinkedCommand = SO301000.DocumentDetails.DiscountAmount, Commit = true });
            }

        }

        cmds.Add(SO301000.Actions.Save);
        cmds.Add(SO301000.OrderSummary.OrderNbr);
        cmds.Add(SO301000.OrderSummary.OrderTotal);
        cmds.Add(SO301000.OrderSummary.TaxTotal);
        cmds.Add(SO301000.OrderSummary.Location);
        cmds.Add(SO301000.OrderSummary.Customer);

        SO301000Content[] SO30100content = context.SO301000Submit(cmds.ToArray());

然而,我得到的错误如下:

PX.Data.PXException:错误#12:插入&#39;销售订单折扣明细&#39;记录引发一个或多个错误。请查阅。错误:&#39;输入&#39;可能不是空的。 ---&GT; PX.Data.PXOuterException:错误#12:插入&#39;销售订单折扣明细&#39;记录引发一个或多个错误。请查看。

您可以在我的代码中看到我分配的&#34; Group&#34;到&#34; SO301000.DiscountDetails.Type&#34;显然,这与设置的折扣代码完全一样 - 我不明白为什么我仍然会收到错误...

感谢。

0 个答案:

没有答案