Dynamics GP Web服务:使用批量分配创建SalesInvoice

时间:2011-06-24 19:53:21

标签: web-services dynamics-gp

我正在尝试使用以下代码基于现有的SalesOrder创建新的SalesInvoice:

SalesInvoice invoice = new SalesInvoice();

invoice.DocumentTypeKey = new SalesDocumentTypeKey { Type = SalesDocumentType.Invoice };
invoice.CustomerKey = originalOrder.CustomerKey;
invoice.BatchKey = originalOrder.BatchKey;
invoice.Terms = new SalesTerms { DiscountTakenAmount = new MoneyAmount { Value = 0, Currency = "USD", DecimalDigits = 2 }, DiscountAvailableAmount = new MoneyAmount { Value = 0, Currency = "USD", DecimalDigits = 0 } };
invoice.OriginalSalesDocumentKey = originalOrder.Key;

List<SalesInvoiceLine> lineList = new List<SalesInvoiceLine>();
for (int i = 0; i < originalOrder.Lines.Length; i++)
{
    SalesInvoiceLine line = new SalesInvoiceLine();
    line.ItemKey = originalOrder.Lines[i].ItemKey;
    line.Key = new SalesLineKey { LineSequenceNumber = originalOrder.Lines[i].Key.LineSequenceNumber; }

    SalesLineLot lot = new SalesLineLot();
    lot.LotNumber = originalOrder.Lines[i].Lots[0].LotNumber;
    lot.Quantity = new Quantity { Value = 2200 };
    lot.Key = new SalesLineLotKey { SequenceNumber = originalOrder.Lines[i].Lots[0].Key.SequenceNumber };
    line.Lots = new SalesLineLot[] { lot };
    line.Quantity = new Quantity { Value = 2200 };
    lineList.Add(line);
}
invoice.Lines = lineList.ToArray();

DynamicsWS.CreateSalesInvoice(invoice, DynamicsContext, DynamicsWS.GetPolicyByOperation("CreateSalesInvoice", DynamicsContext));

执行时,我收到以下错误:

SQL Server Exception: Operation expects a parameter which was not supplied.

动态异常控制台中更详细的例外:

Procedure or function 'taSopLotAuto' expects parameter '@I_vLNITMSEQ',
which was not supplied.

经过大量的Google挖掘后,我发现了一些事情。

  1. 'taSopLotAuto'是销售订单处理组件中的一个eConnect程序,它尝试自动填充批次。我不希望自动填充批次,这就是我尝试在代码中手动填充它们的原因。我还将GPS Web服务用户的自动批量履行中的CreateSalesInvoice策略修改为手动批量履行,但这并没有改变调用哪个eConnect程序。
  2. '@ I_vLNITMSEQ'指的是LineSequenceNumber。 LineSequenceNumber和SequenceNumber(Lot本身)必须匹配。在我的情况下,它们都是默认值:16384。此参数不仅在上面的代码中设置,而且还出现在服务器尝试处理的SOAP消息中 - 几乎“未提供”。
  3. 我可以创建一个没有故障的发票没有订单项,但如果我添加订单项则会失败。我不明白为什么我收到一个明显存在的缺失参数的错误。

    有关如何通过Dynamics GP 10.0 Web服务成功创建SalesInvoice的任何想法?

1 个答案:

答案 0 :(得分:1)

也许你乱七八糟地把线条添加到地段:

lot.Key = new SalesLineKey(); 
lot.Key.SalesDocumentKey = new SalesDocumentKey(); 
lot.Key.SalesDocumentKey.Id = seq.ToString();