web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Posting in Inventory Transfer Journal by code

(0) ShareShare
ReportReport
Posted on by

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 ! :)

*This post is locked for comments

I have the same question (0)
  • amedavamshi Profile Picture
    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
    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
    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
    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
    71,699 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
    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
    71,699 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
    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
    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
    71,699 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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

#1
Rahul Shah Profile Picture

Rahul Shah 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans