尝试通过 Web API 在销售订单中添加 "Discount details" 时出现 "Type may not be empty" 错误
Got "Type may not be empty" error when trying to add "Discount details" in a sales order through Web API
我尝试通过网络 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:插入 'Sales Order Discount Detail' 记录引发了一个或多个错误。请查阅。错误:'Type' 可能不为空。 ---> PX.Data.PXOuterException:错误 #12:插入 'Sales Order Discount Detail' 记录引发了一个或多个错误。请审核。
你可以在我的代码中看到我明确地将 "Group" 分配给 "SO301000.DiscountDetails.Type",这与设置的折扣代码完全相同 - 我不明白为什么我仍然收到错误...
谢谢。
好的。我想通了 - 结果 "adding discount details" 代码应该放在添加行项目的代码之后,即我的代码应该更改为:
..........
//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 });
}
}
.........
//add discount details if there is promo code being used in sales order
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 });
}
cmds.Add(SO301000.Actions.Save);
........
我尝试通过网络 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:插入 'Sales Order Discount Detail' 记录引发了一个或多个错误。请查阅。错误:'Type' 可能不为空。 ---> PX.Data.PXOuterException:错误 #12:插入 'Sales Order Discount Detail' 记录引发了一个或多个错误。请审核。
你可以在我的代码中看到我明确地将 "Group" 分配给 "SO301000.DiscountDetails.Type",这与设置的折扣代码完全相同 - 我不明白为什么我仍然收到错误...
谢谢。
好的。我想通了 - 结果 "adding discount details" 代码应该放在添加行项目的代码之后,即我的代码应该更改为:
..........
//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 });
}
}
.........
//add discount details if there is promo code being used in sales order
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 });
}
cmds.Add(SO301000.Actions.Save);
........