AX2012: Update Invent Registration from code


*** Update: 2013-2-4 ***
Credits go to Andy Adamak for spotting a problem with the code below.
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);   
}

** The above is for interest only and comes with no warranties **

Comments

  1. Thanks , I have search for this long time

    ReplyDelete
  2. I have tested , but only one row in InventTrans have right Reciptstatus. Have you the same problem ?

    ReplyDelete
  3. Yes. I wrote this job base on a question from they Dynamics User forum. The guy who tested this code also report similar problem (as added in the post).
    So, more thoughts would need to be added to find the *right* inventTrans to work with.

    ReplyDelete
  4. How to do the return order registration through code?

    ReplyDelete
    Replies
    1. I was writing the above to give an idea on updating invent registration through code. Also note that it needed more effort on picking up the correct inventTrans to update. Unfortunately I didn't build a complete solution so I don't have a definite answer to your question.
      However, I'd guess that return order registration is similar. If you have tried and run into specific errors I'd recommend you to post the question on the AX Forum at (https://community.dynamics.com/ax/default.aspx). I checked there often and there are other experts who voluntarily share their knowledge there.
      Regards.

      Delete
    2. Why you don't want to use simple \Classes\InventUpd_Registered\?
      ***
      InventUpd_Registered inventUpd = InventUpd_Registered::newParameters(...);
      inventUpd.update();
      ***
      Done!

      how to use - for example \Classes\WMSPalletDoMove\moveExpectedReceipt - very simple method ...
      Regards,
      Vitaliy.

      Delete
  5. Anonymous1:12 PM

    Is there any code to run on server

    ReplyDelete

Post a Comment