Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

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???

*This post is locked for comments

  • 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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans