Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Posting in Inventory Transfer Journal by code

Posted on by Microsoft Employee

Hi there,

first, I have to tell I'm new in AX (started 3 weeks ago) and I'm not english speaker so sorry for that.

I'm doing a form to transfer item from one wmsLocation to another without using the implemented solution (so the final user can do it faster, no need to precise all information that dont change).

I've done my form all is ok but now it's time to post the result in the inventory transfer journal. I have found some code on web (https://community.dynamics.com/ax/b/axaptavsme/archive/2013/07/17/inventory-transfer-journal-through-x-code) and all exemple I found are exactly the same (the one linked).

The problem is compiler tell me there is an error in this code and I cant debug because I dont really understand all this code and I didnt found any explanation about "how build journal entry in code", only found this code without comment.

ttsbegin; 
inventJournalTable.clear();
num = new NumberSeq();
num = NumberSeq::newGetNum(InventParameters::numRefTransferId());
inventJournalTable.initFromInventJournalName(InventJournalName::find(InventParameters::find().TransferJournalNameId));
inventJournalTable.Description = "Inventory Transfer Journal";
inventJournalTable.SystemBlocked = true;
inventJournalTable.insert();
inventJournalTrans.clear();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
    
inventJournalTrans.ItemId = CtrlItemId.text();
    
frominventDim.InventLocationId = CtrlLocId.text();
frominventDim.inventSiteId = CtrlSiteId.text();
frominventDim.wMslocationid = CtrlLocFrom.text();
    
toInventDim.InventLocationId = CtrlLocId.text();
toInventDim.InventSiteId = CtrlSiteId.text();
toInventDim.wmslocationid = CtrlLocTo.text();
    
toInventDim = InventDim::findOrCreate(ToinventDim); 
frominventDim = InventDim::findOrCreate(frominventDim); 
    
inventJournalTrans.InventDimId = frominventDim.inventDimId;
inventJournalTrans.initFromInventTable(InventTable::find("1101"));
inventJournalTrans.Qty = CtrlQty.value();   //Insert qty
inventJournalTrans.ToInventDimId = ToinventDim.inventDimId;
inventJournalTrans.TransDate = SystemDateget();
inventJournalTrans.insert();
inventJournalCheckPost = InventJournalCheckPost::newJournalCheckPost(JournalCheckpostType::Post,inventJournalTable);
//inventJournalCheckPost.parmThrowCheckFailed(_throwserror);
//inventJournalCheckPost.parmShowInfoResult(_showinforesult);
inventJournalCheckPost.run(); 
inventJournalTable.SystemBlocked = false;
inventJournalTable.update(); 
ttscommit;

so my first question is : has anybody any idea what is wrong with the red line ?

Here is the compiler output (in french)

8666.Capture3.PNG

It says something like : "Operand types are not compatible with the operator."

Second question : Can anybody explain this code or the logical process to use this Journal so I can understand and increase my skill in AX and not just copy pastaaaaaa.

Thank you a lot for help ! :)

  • amedavamshi Profile Picture
    amedavamshi 25 on at
    RE: Posting in Inventory Transfer Journal by code

    To use this code,which event handler or class need to be used ?

  • Abhijeet Kr  Profile Picture
    Abhijeet Kr 60 on at
    RE: Posting in Inventory Transfer Journal by code

    The mentioned code works perfectly while we are trying to post journal example inventory adjustments with positive quantity but while we try to do the same using negative quantity it throws the error. Has anyone faced similar scenario and have workaround for same.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Posting in Inventory Transfer Journal by code

    Thank you Sukrut, you lead me to the solution, here is the newJournalCheckPost method, returning a "JournalCheckPost" and NOT a "InventJournalCheckPost"

    public static server JournalCheckPost newJournalCheckPost(
        JournalCheckPostType    _journalCheckPostType,
        InventJournalTable      _inventJournalTable)
    {

    JournalCheckPost journalCheckPost;

    //Here is where we get our InventJournalCheckPost

    journalCheckPost = InventJournalCheckPost::construct(_inventJournalTable);

    ...

    ...

    ...

    }
  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Posting in Inventory Transfer Journal by code

    Here we go, I found a solution in the deep web hahaha.

    I just switched my transaction from "inventJournalCheckPost" to "journalCheckPost" and it works (i have just some minor issue to solve)

    Here is my code for now (without declaration block).

    ttsbegin;
                inventJournalTable.clear();
                num = new NumberSeq();
                num = NumberSeq::newGetNum(InventParameters::numRefTransferId());
                inventJournalTable.initFromInventJournalName(InventJournalName::find(InventParameters::find().TransferJournalNameId));
                inventJournalTable.Description = "Inventory Transfer Journal";
                inventJournalTable.SystemBlocked = true;
                inventJournalTable.insert();
                inventJournalTrans.clear();
                inventJournalTrans.initFromInventJournalTable(inventJournalTable);
    
                inventJournalTrans.ItemId = CtrlItemId.text();
    
                frominventDim.InventLocationId = CtrlLocId.text();
                frominventDim.inventSiteId = CtrlSiteId.text();
                frominventDim.wMslocationid = CtrlLocFrom.text();
    
                toInventDim.InventLocationId = CtrlLocId.text();
                toInventDim.InventSiteId = CtrlSiteId.text();
                toInventDim.wMslocationid = CtrlLocTo.text();
    
                toInventDim = InventDim::findOrCreate(ToinventDim);
                frominventDim = InventDim::findOrCreate(frominventDim);
    
                inventJournalTrans.InventDimId = frominventDim.inventDimId;
                inventJournalTrans.initFromInventTable(InventTable::find(CtrlItemId.text()));
                inventJournalTrans.Qty = CtrlQty.value();   //Insert qty
                inventJournalTrans.ToInventDimId = ToinventDim.inventDimId;
                inventJournalTrans.TransDate = SystemDateget();
                inventJournalTrans.insert();
            
                journalCheckPost = inventJournalCheckPost::construct(inventJournalTable);
                journalCheckPost = inventJournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post,inventJournalTable);
                journalCheckPost.parmThrowCheckFailed(_throwserror);
                journalCheckPost.parmShowInfoResult(_showinforesult);
                journalCheckPost.run();
                //inventJournalCheckPost = inventJournalCheckPost::construct(inventJournalTable);
                //inventJournalCheckPost = InventJournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post,inventJournalTable);
                //inventJournalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);
                //inventJournalCheckPost.parmThrowCheckFailed(_throwserror);
                //inventJournalCheckPost.parmShowInfoResult(_showinforesult);
                //inventJournalCheckPost.run();
                inventJournalTable.SystemBlocked = false;
                //inventJournalTable.update();
            ttscommit;


  • Verified answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,645 Moderator on at
    RE: Posting in Inventory Transfer Journal by code

    You have to debug the code and see what type of object is returned from newJournalCheckPost method . Did you check that?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Posting in Inventory Transfer Journal by code

    Hello there

    here is my declaration block :

    InventJournalTable      inventJournalTable;
    InventJournalTrans      inventJournalTrans;
    InventJournalCheckPost  inventJournalCheckPost;
    NumberSeq               num;
    boolean                 _throwserror = true;
    boolean                 _showinforesult = true;
    InventDim               fromInventDim,toInventDim;
    ;


  • Sukrut Parab Profile Picture
    Sukrut Parab 71,645 Moderator on at
    RE: Posting in Inventory Transfer Journal by code

    What type you have declared for inventJournalCheckPost  ? operand types error comes when you try to assign  something which is  not same type of variable  to the  object you are assigning. For example id you try to assign integer to string you will get this error.  

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Posting in Inventory Transfer Journal by code

    Going to week end,

    I hope I will find some advices monday.

    Regards,

    Stephane

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Posting in Inventory Transfer Journal by code

    thanks for all theese usefull information !

    And yes this is the red line which return an error.

    Tell me if I can give you more usefull details

  • Sukrut Parab Profile Picture
    Sukrut Parab 71,645 Moderator on at
    RE: Posting in Inventory Transfer Journal by code

    Above code is to create Inventory  transfer journal . First part is creation of Journal header (InventJournalTable) then assigning From inventory dimensions and To inventory dimensions (Inventory dimensions are from warehouse , To warehouse etc..) and then Create  Journal Lines (InventJournalTrans) . Once the Journal is created InventJournalCheckPost is used to post journal .

    Now regarding your error - Did you debug and checked if the error is coming from the above highlighted line or from some other line ? If you look at the  newJournalCheckPost method you will understand the run method belongs to JournalCheckPost class.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

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,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,126 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans