Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

How to create Inventory Movement Journal through x++

(0) ShareShare
ReportReport
Posted on by 100

Hi Experts,

I want to write a code in X in MAP- InventInventoryJournalEntryMap in method -setJournalNumber with following condition.

1- If the JournalType = Movement and “Original journal No.” field has value.

2- If the existing Journal is “blocked” by system or any user.


If any condition fulfilled then a new journal movement will be created.

I have written a code for this but getting error.

[ExtensionOf(mapstr(InventInventoryJournalEntryMap))]
public final class CreateInventoryMomentJournal_CAP_Extension
{
    public static void setJournalNumber( InventJournalType   _expectedJournalType,int64 _approxNumberOfLines = 1000)
    {
       
       // next setJournalNumber();
           
            InventJournalTable                  inventJournalTable;
            InventJournalTrans                  inventJournalTrans;
            InventJournalNameId                 inventJournalNameId;
            InventJournalName                   inventJournalName;
            InventDim                           inventDim;
            DimensionAttributeValueCombination  dimAttrValueCombo;
            JournalCheckPost                    journalCheckPost;
            int                                 numOfLines = 0;

            select forupdate inventJournalTable
            where inventJournalTable.JournalType == InventJournalType::Movement && inventJournalTable.JournalIdOrignal
            ||  inventJournalTable.SystemBlocked == true;
    
            if (inventJournalTable)
          //  if (( inventJournalTable.JournalType == InventJournalType::Movement && inventJournalTable.JournalIdOrignal ) || inventJournalTable.SystemBlocked == true)
            {
                ttsbegin;
                inventJournalTable.clear();
                inventJournalNameId =  InventJournalName::standardJournalName(InventJournalType::Movement);
                inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalNameId));
                inventJournalTable.insert();

                inventJournalTrans.clear();
                inventJournalTrans.initFromInventJournalTable(inventJournalTable);
                inventJournalTrans.TransDate = systemDateGet();
                inventJournalTrans.ItemId = '1000';
                inventJournalTrans.initFromInventTable(InventTable::find(inventJournalTrans.ItemId));
                inventJournalTrans.Qty = 1;
                inventdim.InventSiteId = '1';
                inventdim.InventLocationId = '11';
                inventJournalTrans.InventDimId = InventdIm::findOrCreate(inventDim).inventDimId;

                dimAttrValueCombo.clear();

                select firstonly RecId from  dimAttrValueCombo
                where dimAttrValueCombo.MainAccount == MainAccount::findByMainAccountId("110110").RecId
                && dimAttrValueCombo.DisplayValue == '110110';
          
                inventJournalTrans.LedgerDimension = dimAttrValueCombo.RecId;

                if(inventJournalTrans.Qty > 0)
                {
                numOfLines  ;
                inventJournalTrans.insert();
                }

                inventJournalTable.NumOfLines = numOfLines;
                inventJournalTable.update();
                ttscommit;
                  info(strFmt("Movement Journal ID: %1", inventJournalTable.JournalId));
            }
                // journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);
                //journalCheckPost.run();
    }

}
5344.Capture.PNG

  • Alex VN Profile Picture
    Alex VN 1,994 on at
    RE: How to create Inventory Movement Journal through x++

    Hi,

    I think the message is rather clear. The method you extend is not a static method but in your extension it is static. Hence I think ou need to remove static key.

    public static(remove) void setJournalNumber

  • Suggested answer
    huijij Profile Picture
    huijij 19,811 on at
    RE: How to create Inventory Movement Journal through x++

    Hi HARISH,

    For the error message, the COC method must have the final keyword, and the Wrapper methods must always call next method, I think you need to read Microsoft Doc carefully.

    learn.microsoft.com/.../method-wrapping-coc

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans