使用GP Web服务:如何从SalesOrder中删除SalesOrderLine?

时间:2015-12-04 12:33:43

标签: microsoft-dynamics

有人可以帮我从SalesOrder中删除SalesOrderLine吗?

我正在使用GP WS Native Endpoint

我的代码执行时没有错误。

但是,在更新SalesOrder之后,我删除的行仍然存在。

var salesDocumentKeyObject = new SalesDocumentKey {Id = salesDocumentKey, CompanyKey = this.CompanyKey};

var salesOrder = this.DynamicsGpClient.GetSalesOrderByKey(salesDocumentKeyObject, this.Context);

var newLines = salesOrder.Lines.Where(l => l.Key.LineSequenceNumber != lineItemSequence).ToArray();

salesOrder.Lines = newLines;

var salesOrderUpdatePolicy =      this.DynamicsGpClient.GetPolicyByOperation("UpdateSalesOrder", this.Context);

this.DynamicsGpClient.UpdateSalesOrder(salesOrder, this.Context, salesOrderUpdatePolicy);

感谢您的帮助,

卡尔

1 个答案:

答案 0 :(得分:0)

Microsoft Dynamics GP Web Service的文档和示例很差。

删除销售订单行,检索订单,找到要删除的行并将销售订单行属性设置为DeleteOnUpdate为true,然后保存订单。

以下更新的代码:

var salesDocumentKeyObject = new SalesDocumentKey {Id = salesDocumentKey, CompanyKey = this.CompanyKey};
var salesOrder =    this.DynamicsGpClient.GetSalesOrderByKey(salesDocumentKeyObject, this.Context);

var target= salesOrder.Lines.FirstOrDefault(l => l.Key.LineSequenceNumber == lineItemSequence);
if (target != null) {
target.DeleteOnUpdate = true;
}

var salesOrderUpdatePolicy = this.DynamicsGpClient.GetPolicyByOperation("UpdateSalesOrder", this.Context);

this.DynamicsGpClient.UpdateSalesOrder(salesOrder, this.Context, salesOrderUpdatePolicy);