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 :
Finance | Project Operations, Human Resources, ...
Answered

Create Counting Journal in AX2012 through X++ Code

(0) ShareShare
ReportReport
Posted on by 758

Hi Everyone,

Need urgent help.

I want to create Counting Journal through X++ code.

So I have created two Jobs one for creating Journal and another is to add Lines into Journal.

Could anyone please review my code and let me know if I am skipping any parameter and which I should add it to my code?

Though the Journals are getting created through below Jobs , I want to review my Code mentioned below,

Also please reply what does the line "inventJournalTable.InventDimFixed = " signify in Create Journal code ? What value I should pass into it?

///Create Journal/<Start>

static void createCountingJournal_RR(Args _args)
{
InventParameters inventParameters=InventParameters::find();
InventJournalName inventJournalName;
InventJournalTable inventJournalTable;
;
inventJournalTable.selectForUpdate(true);
inventJournalName = InventJournalName::find(inventParameters.CountJournalNameId);
inventJournalTable.initFromInventJournalName(inventJournalName);
inventJournalTable.InventDimFixed = 255;
inventJournalTable.insert();
info("Counting Journal created");

}

///Create Journal/<End>

///Create Journal Lines/<Start>

static void createCountingJournalLines_RR(Args _args)
{

InventTable _inventTable;
InventJournalTable _inventJournalTable = InventJournalTable::find("00082");
InventDim _inventDimFrom;
Qty _qty = 4;
InventJournalTrans inventJournalTrans;
InventDimParm inventDimParm;
InventMov_Jour_Loss_Sumup movement;
InventSum inventSum;
;

select firstOnly inventSum where inventSum.ItemId == "L0101";
select _inventDimFrom where _inventDimFrom.inventDimId == inventSum.InventDimId;
info(inventSum.InventDimId);
_inventTable = InventTable::find(inventSum.ItemId);
inventDimParm.initFromInventDim(_inventDimFrom);
inventJournalTrans.selectForUpdate(true);
inventJournalTrans.initFromInventJournalTable(_inventJournalTable);
inventJournalTrans.initFromInventTable(_inventTable);

inventJournalTrans.InventDimId = _inventDimFrom.inventDimId;
inventJournalTrans.InventOnHand = InventSumDatePhysicalDim::onHandQty(systemDateGet(),_inventTable.itemId,_inventDimFrom,inventDimParm);
inventJournalTrans.Counted = _qty;
inventJournalTrans.TransDate = 20\06\2013;

movement = InventMov_Jour_Loss_Sumup::newFromInventJournalTrans(inventJournalTrans);
movement.journalSetCounted();

inventJournalTrans.setCostPrice(inventJournalTrans.InventDimId);

inventJournalTrans.insert();
info("Counting Journal Line created");
}

///Create Journal Lines/<End>

Thank you in advance.

I have the same question (0)
  • Verified answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Hi,

    Have you seen and checked the following blog post?

    samairaj.wordpress.com/.../

    Best regards,

    Ludwig

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Hello Rhushikesh Raut,

    Have you seen the blog post shared above?

    Did it help and did you get your issue fixed in the meantime?

    Would be great if you could keep us informed whether additional help is required.

    Many thanks,

    Ludwig

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    299,403 Super User 2025 Season 2 on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Hi Rhushikesh,

    You ask us to review the code which is impossible without knowing the exact business requirement. If it is related to a customer requirement, can you then specify why it is not possible to manually create a new journal and use the dialog to specify what would be the contents of the count journal, e.g. which warehouse, which items, which date?

    You have now two separate jobs with all kind of hard coded values which is far from recommended. Two jobs are not suitable for business users. Then you can better create a class with a dialog and then also create a menu item for the user. You also asked about the field InventDimFixed. Have you reviewed what value is used when you create a count journal manually?

    Instead of using the tables for the inventory journals directly, you can also consider using the classes InventJournalTableData and InventJournalTransData. These classes are using business logic to set certain fields correctly, like number sequence etc.

  • Rhushikesh R Profile Picture
    758 on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Hi Andre,

    Sorry for replying late.

    Actually my requirement was to find out the the On hand transactions having Available Physical greater than zero and add the same Item transactions lines into Counting journal.

    The purpose was to make On hand inventory zero.

    As you asked me to review InventDimFixed value in InventJournalTable for manually created Journals, I found out the value as 2097637 for Counting Journals.

    Below is my modified X job. I have combined both jobs.

    static void CHI_createCountingJournal_RR(Args _args)
    
    {
        InventParameters           inventParameters=InventParameters::find();
        InventJournalName          inventJournalName;
        InventJournalTable         inventJournalTable, inventJournalTableUpd;
        InventTable                inventTable;
        InventOnhand               inventOnhand;
        InventDim                  inventDimFrom;
        Qty                        countedQty;
        InventJournalTrans         inventJournalTrans;
        InventDimParm              inventDimParm;
        InventMov_Jour_Loss_Sumup  movement;
        InventSum                  inventSum;
        int                        linenum;
        ;
    
        inventJournalTable.selectForUpdate(true);
    
        inventJournalName = InventJournalName::find(inventParameters.CountJournalNameId);
        inventJournalTable.initFromInventJournalName(inventJournalName);
    
        inventJournalTable.InventDimFixed = 2097637;
        inventJournalTable.insert();
    
        info(strFmt("Counting Journal created %1", inventJournalTable.JournalId));
    
        while select firstOnly InventDimId,ItemId from inventSum
        index hint ItemDimIdx
        {
            select inventDimFrom where inventDimFrom.inventDimId == inventSum.InventDimId;
            inventDimParm.initFromInventDim(inventDimFrom);
            inventOnhand = InventOnhand::newParameters(inventSum.ItemId, inventDimFrom, inventDimParm);
    
            if(inventOnhand.availPhysical() > 0)
            {
                inventJournalTrans.clear();
                //info(strFmt("%1, %2",inventOnhand.availPhysical(), inventSum.InventDimId));
                inventTable = InventTable::find(inventSum.ItemId);
                inventDimParm.initFromInventDim(inventDimFrom);
                inventJournalTrans.selectForUpdate(true);
                inventJournalTrans.initFromInventJournalTable(inventJournalTable);
                inventJournalTrans.initFromInventTable(inventTable);
                inventJournalTrans.InventDimId = inventDimFrom.inventDimId;
                inventJournalTrans.InventOnHand = inventOnhand.availPhysical();//InventSumDatePhysicalDim::onHandQty(systemDateGet(),inventTable.itemId,inventDimFrom,inventDimParm);
                inventJournalTrans.Counted = countedQty;
                inventJournalTrans.TransDate = systemDateGet();
    
                movement = InventMov_Jour_Loss_Sumup::newFromInventJournalTrans(inventJournalTrans);
                movement.journalSetCounted();
    
                inventJournalTrans.setCostPrice(inventJournalTrans.InventDimId);
    
                inventJournalTrans.insert();
    
                linenum  ;
            }
        }
    
        info("Counting Journal Line created");
    
        ttsBegin;
    
        select firstOnly forUpdate JournalId,NumOfLines from inventJournalTableUpd where inventJournalTableUpd.JournalId == inventJournalTable.JournalId;
    
        inventJournalTableUpd.NumOfLines = linenum;
        inventJournalTableUpd.update();
    
        ttsCommit;
    
    }

    Can you please tell me the significance of InventDimFixed  field?

    As per my initial observations the Journal and its lines are getting created from above modified job.

    Thanks for help.

  • Rhushikesh R Profile Picture
    758 on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Hi Ludwig,

    Yes the link is informative. Thanks for help.  I will be verifying both answers soon.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    299,403 Super User 2025 Season 2 on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Hi Rhushikesh,

    I think you can be almost proud of yourself. It looks much better. Also the purpose is clear to me now. Note that if you are using the option 'Use rich formatting' on this forum, you can paste the code in a code applet; then the coding is easier to read. I have changed the last one for you.

    In your script, you have now a line with the next statement:

    while select firstOnly  InventDimId,ItemId from inventSum

    The firstonly command will cause to fetch only one record. Depending how many variations you have in sites, warehouses, locations, colors, serialnumbers, etc, the journal might become very large if you want to count every single dimension.

    The value of the field InventDimFixed represents an InventDimId of the table InventDim. The record has the indication which warehouse, location, color, size, etc is used for a certain transaction. The combination is definitely specific for your environment.

  • Rhushikesh R Profile Picture
    758 on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Hi Andre,

    Thanks for your information. I will start using rich formatting for code snippet from today onward.

    Now wanted to discuss more about field InventDimFixed.

    As per my observations, when I click on New button of Counting Journal Form I get one screen of "Counting by". Please check screenshot below.

    And depending on multiple checkbox selections different InventDimFixed values get generated and assigned into InventJournalTable.

    I am not sure about what happens in actual functionality when we select or deselect multiple checkboxes.

    But when I select all and create one journal manually I get InventDimFixed value as "2097637" in InventJournalTable.

    I tried debugging code but still not able to find out the exact root where this value gets generated. The impacting class name is InventDimFixedClass.

    By any chance could you please help me to get InventDimFixed value through InventDimFixedClass so that the hard coded value will get removed from my Job?

    Thank you.

    6378.CR.png

  • Verified answer
    André Arnaud de Calavon Profile Picture
    299,403 Super User 2025 Season 2 on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Hi Rhushkesh,

    Try to see if your coding is working. The Counting by is used when you generate the journal lines using the journal features. Your coding is different and already looping the inventory by individual dimension (depending on the keyword 'firstonly').

  • Rhushikesh R Profile Picture
    758 on at
    RE: Create Counting Journal in AX2012 through X++ Code

    Thank you Ludwig and Andre for your responses.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,964

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 823 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 564 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans