AX2012: Update Invent Registration from code


This bit of code simply grabs the first InventTransOrigin record where the InventTransID's match, then grabs the FIRST record of the InventTrans table where it matches up with the origin... regardless of status. The issue I was running into was even if it was received/registered, whatever status, it would grab the first InventTrans and override the record and it's InventDim record as well.
So... It works, but not really because it totally messes up all your transactions if you receive more than once against the same PO line
------------------------------------------------------------------------------------------------------------------

Here's a job to update Invent Registration in AX2012. Feel free to try the following job in your testing/development environment.
static void DEV_InventTransRegistrationFromCode(Args _args)
{
    InventTransWMS_Register inventTransWMS_register;
    InventTrans             inventTrans = InventTrans::findTransId( "<inventTransId>");
    InventSerialId          id1 = "<serialId1>", id2 = "<serialId2>" ;
    TmpInventTransWMS       tmpInventTransWMS;
    InventDim               inventDim = inventTrans.inventDim();
   
    inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);
   
    tmpInventTransWMS.clear();
    tmpInventTransWMS.initFromInventTrans(inventTrans);
    tmpInventTransWMS.InventQty = 1;
    inventDim.inventSerialId = id1;
    tmpInventTransWMS.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
    tmpInventTransWMS.insert();
   
    inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS,
                                                   inventTrans,
                                                   inventTrans.inventDim());
   
    tmpInventTransWMS.clear();
    tmpInventTransWMS.initFromInventTrans(inventTrans);
    tmpInventTransWMS.InventQty = 1;
    inventDim.inventSerialId = id2;
    tmpInventTransWMS.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
    tmpInventTransWMS.insert();
   
    inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS,
                                                   inventTrans,
                                                   inventTrans.inventDim());
   
    inventTransWMS_register.updateInvent(inventTrans);   
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.