Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

If I use Disposition Code ID 41, the registration for the return order line does not happen

(4) ShareShare
ReportReport
Posted on by 30
Can you please suggest a way to register the return order line with Disposition Codes 41, 51, and 61? Below is my code.
class BAS_inventoryRegistrationHelper
{
    public static void inventoryRegistration(SalesId _salesId)
    {
        boolean     result;
        SalesLine     salesReturnOrderRegisterLine;
        SalesLine                       salesLine;
        TmpInventTransWMS               tmpInventTransWMS;
        InventTransWMS_Register         inventTransWMS_Register;
        InventDim                       inventDim;
        InventTrans                     inventTrans;
        VendPackingSlipTrans            vendPackingSlipTransLoc;
        InventTransOrigin               inventTransOrigin;
        SalesReturnOrderLineRegister    salesReturnOrderLineRegister;
        while select salesReturnOrderRegisterLine
         where salesReturnOrderRegisterLine.SalesId == _salesId
        {
            salesLine =  BAS_inventoryRegistrationHelper::updateDispositionCode(salesReturnOrderRegisterLine.InventTransId);
            inventTransWMS_Register = InventTransWMS_Register::newStandard(tmpInventTransWMS);
            select firstonly inventTrans
            where inventTrans.StatusReceipt == StatusReceipt::Ordered
            exists join inventTransOrigin
                where inventTransOrigin.RecId == inventTrans.InventTransOrigin
                &&    inventTransOrigin.InventTransId == salesLine.InventTransId
                &&    inventTransOrigin.ReferenceId == _salesId;
     
            tmpInventTransWMS.clear();
            tmpInventTransWMS.initFromInventTrans(inventTrans);
            //tmpInventTransWMS.InventQty     = salesReturnOrderRegisterLine.SalesQty;
            tmpInventTransWMS.LineNum       = salesLine.LineNum;
            inventDim                       = salesLine.inventDim();
            //inventDim.inventSerialId        = salesReturnOrderRegisterLine.inventSerialId;
            //inventDim.inventBatchId         = salesReturnOrderRegisterLine.inventBatchId;
            tmpInventTransWMS.InventDimId   = InventDim::findOrCreate(inventDim).inventDimId;
            tmpInventTransWMS.ItemId        = salesLine.ItemId;
            //tmpInventTransWMS.insert();
            inventTransWMS_Register.writeTmpInventTransWMS(tmpInventTransWMS, inventTrans, InventDim::find(tmpInventTransWMS.InventDimId));
            select * from salesLine;
            if (!inventTransWMS_Register.updateInvent(salesLine))
            {
                throw error("Error during sales return order registration");
            }
        }
    }
    public static SalesLine updateDispositionCode(InventTransId _inventTransId)
    {
        SalesLine               salesLine = SalesLine::findInventTransId(_inventTransId, true);
        ReturnDispositionCode   returnDispositionCode;
        BAS_inventoryRegistrationHelper::runPreReturnOrderRegisterLine(salesLine);
        ttsbegin;
        salesLine.ReturnDispositionCodeId = returnDispositionCode.DispositionCodeId;
        salesLine.update();
        ttscommit;
        return salesLine;
    }
    public static void runPreReturnOrderRegisterLine(SalesLine _salesLine)
    {
        InventTransOriginId     salesLineInventTransOriginId;
        InventTransOriginId     reservationLineInventTransOriginId;
        SalesLine               reservationLine;
        ReturnDispositionCode   returnDispositionCode;
        if (_salesLine.ReturnStatus == ReturnStatusLine::Awaiting)
        {
            if (!_salesLine.ReturnAllowReservation &&  _salesLine.isStocked())
            {
                SalesLine::changeReturnOrderType(_salesLine.InventTransId);
                _salesLine = SalesLine::findInventTransId(_salesLine.InventTransId, true);
            }
            select firstOnly returnDispositionCode
                where returnDispositionCode.DispositionAction == DispositionAction::ReplaceScrap;
            ttsbegin;
            select forupdate reservationLine
                where reservationLine.SalesId == _salesLine.SalesId;
            _salesLine.ReturnDispositionCodeId = returnDispositionCode.DispositionCodeId;
            _salesLine.update();
            ttscommit;
        }
        else if (_salesLine.ReturnStatus == ReturnStatusLine::Registered)
        {
            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");
                }
            }
        }
    }
}
 
Categories:
  • Suggested answer
    Holly Huffman Profile Picture
    6,078 on at
    If I use Disposition Code ID 41, the registration for the return order line does not happen
    Hi there! Good morning, evening, or afternoon - depending on where you are :) Hope you are well today! 
     
    To successfully register return order lines with Disposition Codes like 41, 51, and 61, you may need to adjust how the disposition codes and their respective actions are handled within your code. Here are some suggestions and considerations:
     
    1. Verify Disposition Code Setup
    • Ensure that Disposition Codes 41, 51, and 61 are properly set up in the system (e.g., with correct mappings to their DispositionAction types).
    • Double-check if these codes are assigned appropriate DispositionAction values (ReplaceScrap, ReturnToCust, Scrap, etc.) that align with your business logic.
    2. Modify Logic for Handling Disposition Codes
    • In the updateDispositionCode method, make sure that ReturnDispositionCode is being correctly fetched and applied.
    • Replace:
      select firstOnly returnDispositionCode where returnDispositionCode.DispositionAction == DispositionAction::ReplaceScrap;

      With:
      select firstOnly returnDispositionCode where returnDispositionCode.DispositionCodeId == _desiredDispositionCodeId;

      This ensures that the correct disposition code is used dynamically based on the input.
    3. Validate Return Status Logic
    • Ensure that the ReturnStatus for the SalesLine is updated before applying the disposition code. For example:
      • If the return status is Awaiting, ensure the disposition action aligns with the intended workflow.
      • If the status is Registered, confirm that the inventory marking and reservations are handled properly.
    4. Adjust Inventory Registration Logic
    • In the inventoryRegistration method, validate how the tmpInventTransWMS object is being initialized:
      • Ensure it reflects the right inventory dimensions (InventDim) and item properties for the return line.
    5. Debug Error Handling
    • If errors occur during registration, expand the error message (throw error) to include details about the disposition code and inventory data being processed. This can help pinpoint issues.
    6. Test the Workflow
    • Create test scenarios for return orders with Disposition Codes 41, 51, and 61. Validate the following:
      • Lines are registered correctly based on their disposition codes.
      • The inventory actions (e.g., InventTrans, InventTransOrigin) align with the disposition code logic.
    Example Adjustments:
    Here’s a potential tweak for the updateDispositionCode logic:
    public static SalesLine updateDispositionCode(InventTransId _inventTransId, DispositionCodeId _desiredDispositionCodeId)
    {
        SalesLine salesLine = SalesLine::findInventTransId(_inventTransId, true);
        ReturnDispositionCode returnDispositionCode;
       
        select firstOnly returnDispositionCode
            where returnDispositionCode.DispositionCodeId == _desiredDispositionCodeId;
       
        if (!returnDispositionCode)
        {
            throw error("Invalid Disposition Code ID");
        }

    ttsbegin;
        salesLine.ReturnDispositionCodeId = returnDispositionCode.DispositionCodeId;
        salesLine.update();
        ttscommit;

    return salesLine;
    }

    Additional Considerations
    • If Disposition Codes require special handling (e.g., unique inventory updates), you might need to add custom logic to inventTransWMS_Register.updateInvent() or elsewhere in your helper class.
    • Ensure the actions tied to the disposition codes (like ReplaceScrap) are supported by your inventory posting logic.
     
     
    Hope this helps some!

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 61 Most Valuable Professional

#3
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 53 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans