Christopher Kane

Ramblings of a Software Architect

Recent posts

Tags

Categories

Navigation

Pages

Archive

Blogroll

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

(SOLVED) Dynamics AX 2009 – Receive Purchase Order Line using x++ & .Net Business Connector

We needed to expose a WCF service so that our logistics vendors could execute a purchase order
line receipt. There were a lot of results returned from a google & yahoo search but a good portion
of them weren’t very specific. After hours of trial and error I came up with the x++ code below
that includes a serial number update through the Inventory Dimension.
public static void receivePurchLine(PackingSlipId _packSlipId, PurchId _purchId,
                                  Qty _qty, ItemId _itemId, LineNum _lineNum, str _inventLocation)
{
    PurchFormLetter purchFormLetter;
    ParmId parmId;
    PurchParmTable purchParmTable;
    PurchParmLine purchParmLine;
    PurchTable purchTable;
    PurchLine purchLine;
    InventDim currentInventDim;
    InventDim updatedInventDim;
    ;

    purchTable = PurchTable::find(_purchId);
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
    purchFormLetter.createParmUpdate();
    purchFormLetter.createParmTable(purchParmTable, purchTable);
    purchParmTable.Num = _packSlipId;
    purchParmTable.insert();
    while select purchLine
        where purchLine.PurchId == purchTable.PurchId
    {
        purchParmLine.InitFromPurchLine(purchLine);
        purchParmLine.ParmId = purchParmTable.ParmId;
        purchParmLine.TableRefId = purchParmTable.TableRefId;
        if (purchLine.ItemId == _itemId && purchLine.LineNum == _lineNum)
        {
            currentInventDim = InventDim::find(purchLine.InventDimId);
            if (currentInventDim.RecId)
            {
                updatedInventDim = 
InventDim::findOrCreateOwnCondDispSiteLocation(currentInventDim.configId, currentInventDim.InventSizeId, currentInventDim.InventColorId, currentInventDim.InventSiteId, _inventLocation); if (!updatedInventDim.RecId) { throw error('Unable to find or create destination inventory dimension'); } } purchParmLine.ReceiveNow = _qty; purchParmLine.RemainAfter = purchLine.QtyOrdered - _qty; purchParmLine.InventDimId = updatedInventDim.inventDimId; } else { purchParmLine.ReceiveNow = 0; purchParmLine.RemainAfter = purchLine.QtyOrdered; } purchParmLine.setQty(DocumentStatus::PackingSlip, false, true); purchParmLine.setLineAmount(); purchParmLine.insert(); } purchFormLetter.proforma (false); // proforma ? purchFormLetter.printFormLetter(false); // print ? purchFormLetter.specQty (PurchUpdate::All); // what to update? purchFormLetter.transDate (today()); // update date purchFormLetter.run(); }

 

Posted: Jan 17 2010, 08:14 by ckane | Comments (1) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Traslochi aziendali Italy said:

Traslochi aziendaliNice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!

# July 21 2010, 16:49

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading