Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Registration for return order line x++

Posted on by Microsoft Employee

Hi I need to do the registration for Return order lines, I provide the following link is how the final user does the registration for the Return Order Line (From step 17 to 22):

community.dynamics.com/.../return-order-in-ax-2012-r3

I need to do the same thing but by code

Some know how I can do it???

  • Suggested answer
    RE: Registration for return order line x++

    Hi Davut,

    Thank you very much for your reply, I got the solution. below is the method I have used and it is working fine.

    public void createRegisterline(SalesTable _salestable)

    {

       Integer                                 lastRec = 0;

       SalesId                                 oldSalesId;

       inventTrans                             inventTrans;

       SalesFormLetter                         salesFormLetter;

       inventTransOrigin                       inventTransOrigin;

       TradeOrderLineRegister                  tradeOrderlineRegister;

        autoRegistrationSBC           salesReturnOrderLineRegister;

       InventTransWMS_Register                 inventTransWMS_register;

       TmpInventTransWMS                       TmpInventTransWMS;

       ReturnDispositionCode                   returnDispositionCode;

       Description255                          errorMsg;

       Args _args = new Args();

       try

       {

           ttsBegin;

           select firstOnly * from returnDispositionCode

               where returnDispositionCode.DispositionAction == DispositionAction::Credit;

           while  select forUpdate salesLine

               where _salestable.SalesId  == salesLine.SalesId

               && _salestable.SalesType == SalesType::ReturnItem

           {

               try

               {

                   _args.record(salesLine);

                   tradeOrderLineRegister = autoRegistrationSBC::construct();

                   tradeOrderLineRegister.parmArgs(_args);

                   tradeOrderLineRegister.init();

                   salesReturnOrderLineRegister = tradeOrderLineRegister;

                   salesReturnOrderLineRegister.runPreSuper();

                   //update returnDisposioncode

                   salesLine.ReturnDispositionCodeId = returnDispositionCode.DispositionCodeId;

                   salesLine.update();

                   select firstOnly crossCompany inventTrans

                       join RecId,InventTransId from inventTransOrigin

                           where inventTransOrigin.InventTransId == salesLine.InventTransId

                           && inventTrans.InventTransOrigin == inventTransOrigin.RecId;

                   inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);

                   tmpInventTransWMS.clear();

                   tmpInventTransWMS.initFromInventTrans(inventTrans);

                   tmpInventTransWMS.InventDimId = inventTrans.InventDimId;

                   tmpInventTransWMS.insert();

                   inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS,

                                                                  inventTrans,

                                                                  inventTrans.inventDim());

                   inventTransWMS_register.updateInvent(salesLine);

               }

               catch

               {

                   continue;

               }

           }

           ttsCommit;

       }

       catch

       {

           throw error("@SYS332911");

       }

    }

  • davut Profile Picture
    davut 2 on at
    RE: Registration for return order line x++

    hello 

    try this code.

    SalesLine salesLine = SalesLine::findRecId(00000000000);
    InventTransWMS_Register inventTransWMS_register;
    InventTrans inventTrans;
    TmpInventTransWMS tmpInventTransWMS;
    InventDim inventDim;
    InventTransOriginId salesLineInventTransOriginId;
    InventTransOriginId reservationLineInventTransOriginId;
    SalesLine reservationLine;
    ReturnDispositionCode returnDispositionCode;
    SalesReturnOrderLineRegister SalesReturnOrderLineRegister;
    Args args ;
    ;



    if(salesLine)
    {
    if (salesLine.ReturnStatus == ReturnStatusLine::None || salesLine.ReturnStatus == ReturnStatusLine::Awaiting)
    {
    args = new Args();
    args.record(salesLine);
    SalesReturnOrderLineRegister = SalesReturnOrderLineRegister::construct();
    SalesReturnOrderLineRegister.parmArgs(args);
    SalesReturnOrderLineRegister.init();
    SalesReturnOrderLineRegister.runPreSuper();


    salesLine.ReturnDispositionCodeId = "Return";
    salesLine.update();

    }
    inventTrans = InventTrans::findTransId(salesLine.InventTransId);
    inventDim = inventTrans.inventDim();
    inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);

    tmpInventTransWMS.clear();
    tmpInventTransWMS.initFromInventTrans(inventTrans);
    tmpInventTransWMS.InventQty = abs(5);

    //tmpInventTransWMS.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
    tmpInventTransWMS.InventDimId = salesLine.InventDimId;
    tmpInventTransWMS.ItemId = salesLine.ItemId;
    tmpInventTransWMS.LineNum = salesLine.LineNum;
    //tmpInventTransWMS.insert();
    inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS,
    inventTrans,
    inventTrans.inventDim());
    inventTransWMS_register.updateInvent(inventTrans);

    select forupdate firstonly reservationLine where reservationLine.InventRefTransId == salesLine.InventTransId;

    if (reservationLine
    || salesLine.qtyMarked())
    {
    if ((salesLine.returnDispositionCode().DispositionAction == DispositionAction::ReplaceScrap
    || salesLine.returnDispositionCode().DispositionAction == DispositionAction::ReturnToCust
    || salesLine.returnDispositionCode().DispositionAction == DispositionAction::Scrap))
    {
    if (reservationLine.SalesQty == reservationLine.RemainSalesPhysical)
    {
    reservationLineInventTransOriginId = InventTransOriginSalesLine::findInventTransOriginId(reservationLine.DataAreaId, reservationLine.InventTransId);
    salesLineInventTransOriginId = InventTransOriginSalesLine::findInventTransOriginId(salesLine.DataAreaId, salesLine.InventTransId);
    InventTransOrigin::deleteMarking(salesLineInventTransOriginId, reservationLineInventTransOriginId, -salesLine.QtyOrdered);
    reservationLine.delete();
    }
    }
    else
    {
    throw error("@SYS332911");
    }
    }
    }

  • RE: Registration for return order line x++

    Hi Eduardo Cabrera,

    I need to register return order through X++ code so can you please share your working code.

    Thanks in advance 

  • DynAx90 Profile Picture
    DynAx90 865 on at
    RE: Registration for return order line x++

    Can you share your code, because the code you provided is not working 

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Registration for return order line x++

    Hi David, I have created a new class because the previous code has an error for the user.

  • davut Profile Picture
    davut 2 on at
    RE: Registration for return order line x++

    Hi Eduardo

    I've tried this code in a job but nothing happened.

    I am curious about how can I update Qty in this code?

    Thanks

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Registration for return order line x++

    I did this code to registers the Return Order Line, this is the answer to my question, I posted it, if someone has the same issue like me, you only need to set the SalesId and the ReturnDispositionCodeId:

    TradeNonStockedRegisterForm     tradeNonStockedRegisterForm;

    TradeNonStockedRegisterTmp      tradeNonStockedRegisterTmpUpdated;

    SalesLine                                        salesline;

    str                                                   errorMsg = "";

    System.Exception                           error;

    try

    {

       while select forUpdate salesline

           where salesline.SalesId == //SalesId

            && salesline.ReturnStatus == ReturnStatusLine::Awaiting

       {

           salesline.ReturnDispositionCodeId = //ReturnDispositionCodeId;

           ttsBegin;

           salesline.doUpdate();

           ttsCommit;

           tradeNonStockedRegisterForm = TradeNonStockedRegisterForm::newFromSalesPurchLine(salesline);

           tradeNonStockedRegisterForm.populatePendingQuantityRows(tradeNonStockedRegisterTmpUpdated);

           tradeNonStockedRegisterForm.insertFromTradeNonStockedRegisterTmp(tradeNonStockedRegisterTmpUpdated,

               tradeNonStockedRegisterTmpUpdated,

               tradeNonStockedRegisterTmpUpdated.StatusReceipt == StatusReceipt::Ordered?

               tradeNonStockedRegisterTmpUpdated.Quantity : -tradeNonStockedRegisterTmpUpdated.Quantity, true);

          tradeNonStockedRegisterForm.parmSelectedToRegisterNow().in(tradeNonStockedRegisterTmpUpdated.RecId);

          tradeNonStockedRegisterForm.register(tradeNonStockedRegisterTmpUpdated);

       }

    }

    catch (Exception::CLRError)

    {

       error = CLRInterop::getLastException();

       errorMsg = error.ToString();

    }

    tradeNonStockedRegisterForm.populatePendingQuantityRows(tradeNonStockedRegisterTmpUpdated);

    return errorMsg;

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Registration for return order line x++

    Thank you for your answer, I can create a return order but I can't generate the lines for packing slip

  • Suggested answer
    Ajit Profile Picture
    Ajit 8,755 on at
    RE: Registration for return order line x++

    You can refer below link -

    community.dynamics.com/.../529922

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,349 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,212 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans