开发者

Dynamics GP Web Services: SalesInvoice Creation with Lot Allocation

I'm trying to use the following code to create a new SalesInvoice based on an existing SalesOrder:

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开发者_StackOverflow中文版 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));

When executed, I receive the following error:

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

And the more detailed exception from the Exception Console in Dynamics:

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

After a considerable amount of digging through Google, I discovered a few things.

  1. 'taSopLotAuto' is an eConnect procedure within the Sales Order Processing component that attempts to automatically fill lots. I do not want the lots automatically filled, which is why I try to fill them manually in the code. I've also modified the CreateSalesInvoice policy from Automatic lot fulfillment to Manual lot fulfillment for the GP web services user, but that didn't change which eConnect procedure was called.
  2. '@I_vLNITMSEQ' refers to the LineSequenceNumber. The LineSequenceNumber and SequenceNumber (of the Lot itself) must match. In my case they are both the default: 16384. Not only is this parameter set in the code above, but it also appears in the SOAP message that the server attempted to process - hardly "not supplied."

I can create an invoice sans line items without a hitch, but if I add line items it fails. I do not understand why I am receiving an error for a missing parameter that is clearly present.

Any ideas on how to successfully create a SalesInvoice through Dynamics GP 10.0 Web Services?


Maybe you mess to add the line key to the lot:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜