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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to Create General Journal and Lines with Data in Staging Table

(0) ShareShare
ReportReport
Posted on by 117

Hi all,

         I have fetched client's data by conusming a REST API. The data is available in the staging table. I have created a batch job using sysoperation framework. Now, I want to create general journal in that batch job using the data I have in my staging table. The staging table has fields like Account, Description, Debit, Credit.

I have been trying but unable to solve it. Can you please guide me ?

The purpose is when the batch job is run, it should create a new general journal and map the fields on Journal and Lines using the fields in the staging table. I am using D365FO.

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,037 Super User 2025 Season 2 on at

    Hi,

    Can you tell where exactly you get stuck? What exactly do you mean with "unable to solve it"? Do you need table names? Do you get an error somewhere? Please elaborate and if it makes sense, share the coding you have created so far, so we can guide you how to continue.

  • 00030000036294D5 Profile Picture
    117 on at

     
            LedgerJournalTable			ledgerTable;
            LedgerJournalTrans			ledgerTrans;
            NumberSeq					numSeq;
            Voucher						voucher;
            NumberSequenceTable         numSeqTable;
            LedgerJournalName			ledgerJournalName;
            ;
           
    		
    		ttsbegin;
    
            select forupdate ledgerTable;
            numSeq = NumberSeq::newGetNum(LedgerParameters::numRefJournalNum());
            ledgerTable.JournalNum = numSeq.num();
            ledgerTable.JournalName= 'INV';
            ledgerTable.Name       = 'Invoice';
           // ledgerTable.PostedDateTime = systemDateGet();
    
            ledgerTable.insert();
            numSeq.used();
           
    
            while select forupdate ledgerTrans where ledgerTrans.JournalNum == ledgerTable.JournalNum
            {
                try
                {
                    ttsbegin;
    
                    ledgerTrans.clear();
                    ledgerTrans.initValue();
                    ledgerTrans.JournalNum   = ledgerTable.JournalNum;
                    ledgerTrans.TransDate    = systemDateGet();
                    ledgerJournalName = LedgerJournalName::find(ledgerTable.JournalName);
    				select firstOnly numSeqTable
    				where numSeqTable.RecId == ledgerJournalName.NumberSequenceTable;
    				if(numSeqTable)
    				{
                        numSeq = NumberSeq::newGetVoucherFromCode(numSeqTable.NumberSequence);
               
                        voucher = numSeq.voucher();
              
    					ledgerTrans.Voucher = voucher;
    					
    				}
                    if (ledgerTrans.validateWrite())
                    {
                        ledgerTrans.insert();
                    }
    
                    ttscommit;
    
             
                }
                catch(Exception::Error)
                {
                    info("error"));
                }
               
            }
            
           ttscommit;
           
            
       

    @André Arnaud de Calavon I am using this code. Now, the current situation is I am able to create a new journal on the running of my batch job. The JV is also being created. The quesiton is how can I assign the values of account, debit, credit and financial dimension in the JV from my staging table. The staging table has no JournalNum value. It only has Account, debit, credit, financial dimensions related 3 other fields like department and zone. 

    One more thing I have notices that I am unable to find created JV in LedgerJournalTrans table ?? Why is that.. Journal is appearing fine in LedgerJournalTable. 

    The voucher number is also not being created? Is this code's fault or number sequence is not assigned to JV ?? I have found a previous JV in the Journal Trans table which is showing voucher number to a previous JV which was perhaps deleted because I do not see it from the front. 

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,037 Super User 2025 Season 2 on at

    Hi,

    To save you from reinventing the wheel, you can use the classes JournalTableData and JournalTransData which helps you setting values for some fields. There are some features as example where you can check how to use these classes.

    You are currently looping the ledger journal lines for your new journal. However, these lines are not created yet, so the loop is empty. You have to loop your staging table to get the details what should be added as lines in your journal. You mentioned that there is no journal number on the staging table. This should not be a problem. You only need to ensure that you will not get incorrect journals when multiple users or batches are running.

    You can consider adding a particular identification to know which lines belongs together which should be added to your journal. After inserting the journal lines, you can set a status to the staging table records or delete them.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans