AX/D365 Create an inventory counting journal and Post it

 

To follow up on customer requests and create a new function to create an inventory counting journal and Post it with X++, we can use the code below:

static void createInvCountingAndPost(Args _args)

{

    InventJournalName inventJournalName;

    InventJournalTable inventJournalTable;

    InventJournalTrans inventJournalTrans;

    InventDim inventDim;

    InventJournalCheckPost inventjournalCheckPost;

    JournalId journalId;

    InventSum inventSum;

    int numOfLine;

;


    inventJournalName = InventJournalName::find(“YourJournalName”);// Must have           


inventJournalTable.initFromInventJournalName(inventJournalName);

    inventJournalTable.SystemBlocked = true;

    inventJournalTable.insert();

          inventJournalTrans.initFromInventJournalTable(inventJournalTable);

    inventJournalTrans.TransDate = systemdateget();

    inventJournalTrans.ItemId = "YourItemId";


    inventDim.InventSiteId = "YourInventSite";

    inventDim.InventLocationId = "YourInventLocationId";

    inventDim.configId = "InventConfigId";

    inventDim = InventDim::findOrCreate(inventDim);


    inventJournalTrans.InventDimId = inventDim.inventDimId;

inventSum =InventSum::find(inventJournalTrans.ItemId,inventJournalTrans.InventDimId);

    InventSum.reread(); 


    inventJournalTrans.InventOnHand = InventSum.AvailPhysical; 

    inventJournalTrans.Counted = 1200; 

    inventJournalTrans.Qty = inventJournalTrans.Counted -               inventJournalTrans.InventOnHand;

    inventJournalTrans.insert();


    numOfLine++;

    journalId = inventJournalTable.JournalId;

    inventJournalCheckPost =InventJournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post, inventJournalTable);

    inventJournalCheckPost.run();


    update_recordSet inventJournalTable

        setting SystemBlocked = false, NumOfLines = numOfLine

        where inventJournalTable.JournalId == journalId;

}

Comments

Popular posts from this blog

How to customize electronic reporting in D365

Build HTML and send email in D365 FO with X++

Batch parallelism or multithreading in Dynamics 365 for Finance and Operations

How to Enable/Disable a Form Button with X++

How to create and run the Runbase batch class in D365

How to create and run the Runbase class in D365

Customize the standard excel template in D365FO

Difference between InMemory and TempDB tables in D365 F&O

How to create and run a batch class that extends RunBaseBatch in D365

How to apply a package in LCS Dynamics 365 F&O