Monday, January 3, 2011

Marking a Sales Line with Purch Line in Dynamics AX 2009, With X++ Code,

Partial/Complete marking of Sales Line with X++ Code:

static void xppInventMarking(Args _args)
{
    InventTrans                          purchLineTrans;
    InventTrans                          salesLineTrans;
    SalesLine                              salesLine;
    TmpInventTransMark            tmpInventTransMark;
    Map                                      mapMarkNow;
    InventDim                             inventDim;
    MapEnumerator                     mapEnumerator;
    Qty                                       qtyMax;
    container                              con;
    Qty                                       qty;
    TmpInventTransMark             tmpInventTransMarkNow;

   ;

 //Say,Sales Line has sales qty = 10
//Say, Purch Line has PurchQty = 10 and we want to mark only 1, partial
    ttsbegin;
    salesLineTrans            = InventTrans::findTransId('00000451_068', true);
    purchLineTrans           = InventTrans::findTransId('00000452_068', false);

    inventDim                  = purchLineTrans.inventDim();
    salesLine                     = salesLineTrans.salesLine();


    // setup marking
    [con, qty]          = TmpInventTransMark::packTmpMark(salesLine.ItemId, inventDim, salesLine.InventTransId, -10);
    salesLine.SalesQty  = -1;
    mapMarkNow          = Map::create(con);
    mapEnumerator       = mapMarkNow.getEnumerator();

   while (mapEnumerator.moveNext())
      {
         tmpInventTransMark = mapEnumerator.currentValue();
         if (tmpInventTransMark.InventTransId == purchLineTrans.InventTransId)
           {
              break;
           }
      }

   buf2buf(tmpInventTransMark, tmpInventTransMarkNow);
   tmpInventTransMarkNow.qtyMarkNow = salesLine.SalesQty;

   tmpInventTransMarkNow.insert();

   mapMarkNow   = new Map(Types::Integer, Types::Record);
   mapMarkNow.insert(tmpInventTransMarkNow.RecId, tmpInventTransMarkNow);
   salesLineTrans.Qty = -1;
   TmpInventTransMark::updateTmpMark(salesLineTrans.InventTransId, inventDim, -salesLineTrans.Qty, mapMarkNow.pack());
   ttscommit;

}
***************************************

Complete Marking:
PurchLine   purchLine;
SalesLine   salesLine;
;
purchLine = PurchLine::findRecId(“464643344”);
salesLine =  SalesLine::findRecId(“2343464344”);

If (purchLine.RecId)
{
            purchLine.ItemRefType               = InventRefType::Sales;
            purchLine.InventRefId               = salesLine.SalesId;
            purchLine.InventRefTransId          = salesLine.InventTransId;
        purchLine.update();
}
        if (salesLine.RecId)
        {
            salesLine.InventRefType         = InventRefType::Purch;
            salesLine.InventRefId           = purchLine.PurchId;
            salesLine.InventRefTransId      = purchLine.InventTransId;

            salesLine.update();
        }

2 comments:

  1. This is so cool! I'm working on a project that requires to do the markings automatically.

    Thanks!

    ReplyDelete
  2. Concrete Polishers and Epoxy Flooring Specialists in Melbourne

    Employment opportunities for Concrete Polishers and Epoxy Flooring Specialists in Melbourne. Our Commercial Epoxy Flooring Team in Melbourne is looking for qualified, reliable, self driven epoxy applicators and concrete polishers with an attention to details to join our Melbourne Epoxy Flooring team.
    Go T:>> http://www.auscraftgroup.com.au/

    ReplyDelete