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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Getting Errors related to Vouchers & Account Number while Posting the Journal

(0) ShareShare
ReportReport
Posted on by 63

Hi, 

I am getting this errors while posting the journal : Voucher not specified as of today Date & Account No. must be filled in.

Actually, I am working on a task where I am reading some data from a simple text file whose address is provided using Contract class & creating a journal based on file data, I am using Number Sequence class to generate unique voucher's. but at the time of posting I am getting this error & I have tried to give voucher manually in the text file & read & assign to each Transactions but getting the same error again,

I debug the code & found that numberSeq is creating unique vouchers but not stored in the LedgerJournalTrans.Voucher field.

Also, I am confused how to filled this Account Number field which is available on Journal Lines but not directly available in LedgerJournalTrans Table.

I am sharing my code for the reference.

class HSHTGLBatchProcessService extends SysOperationServiceBase
{ 
    /// 
    /// processGLData method process the logic
    /// 
    /// _contract
    public void processGLData(HSHTGLBatchProcessContract _contract)
    {
        str sFileName,sTempPath,sFileContent;
        FileIOPermission fileIoPermission;
        container fields;
        LedgerJournalTable  ledgerJournalTable;
        LedgerJournalTrans  ledgerJournalTrans;
        JournalTableData journalTableData;
        str description, currencyCode;
        real amount;
        NumberSeq numberSeq;
        LedgerJournalCheckPost ledgerJournalValidate, ledgerJournalPost;
        try
        {
            sFileName = _contract.parmFilePath();

            // Get the temporary path
            sTempPath = System.IO.Path::GetTempPath();
            
            numberSeq = NumberSeq::newGetNum(LedgerParameters::numRefAdvancedLedgerEntryVoucher(),true);

            // Initialize the journal header information
            ledgerJournalTable.initvalue();
            journalTableData = JournalTableData::newTable(ledgerJournalTable);
            ledgerJournalTable.JournalType = LedgerJournalType::Daily;
            ledgerJournalTable.JournalNum = journalTableData.nextJournalId();
            ledgerJournalTable.JournalName = @"GL Batch Journal";
            ledgerJournalTable.initFromLedgerJournalTable(ledgerJournalTable);
            ttsbegin;
            if (ledgerJournalTable.validateWrite())
            {
                ledgerJournalTable.insert();
            }
            ttscommit;
            // Assert Permisssion
            fileIoPermission = new FileIOPermission(sTempPath   sFileName, @"RW");
            fileIoPermission.assert();

            // Open the input file for reading.
            System.IO.StreamReader streamReader = new System.IO.StreamReader(sTempPath   sFileName);

            // Read the first line and discard it
            streamReader.ReadLine();
            
            if (ledgerJournalTable.RecId)
            {

            if (streamReader)
            {
                
                while (!streamReader.EndOfStream)
                    {
                        sFileContent = streamReader.ReadLine();

                    // Split the line by comma and create a container
                    fields = list2Con(strSplit(sFileContent,','));

                    // Check that there are exactly four fields
                    if (conLen(fields) == 3)
                    {
                        // Assign the fields to variables
                        description = conPeek(fields, 1);
                        currencyCode = conPeek(fields, 2);
                        amount = str2num(conPeek(fields, 3));
                           
                          
                            // Initialize the journal line information
                            ledgerJournalTrans.clear();
                            ledgerJournalTrans.initValue();
                            ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
                            ledgerJournalTrans.TransDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
                            ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
                            ledgerJournalTrans.CurrencyCode = currencyCode;
                            ledgerJournalTrans.Txt = description;
                            ledgerJournalTrans.Voucher = numberSeq.num();
                            ledgerjournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
                            ledgerjournalTrans.OffsetLedgerDimension = 0;
                            ledgerJournalTrans.Approved = NoYes::Yes;
                            ledgerJournalTrans.SkipBlockedForManualEntryCheck = true;
                            ledgerJournalTrans.defaultRow();

                            // Set the debit or credit amount based on the value in the text file
                            if (amount > 0)
                            {
                                ledgerJournalTrans.AmountCurDebit = amount;
                            }
                            else
                            {
                                ledgerJournalTrans.AmountCurCredit = abs(amount);
                            }

                            // Validate and insert the journal line
                            ttsbegin;

                            if (ledgerJournalTrans.validateWrite())
                            {
                                ledgerJournalTrans.insert();
                            }
                          
                            else 
                            {
                                throw Exception::Error;
                            }
                           
                            ttscommit;
                    }
                    
                        numberSeq.used();
                        info(strFmt(@"Voucher : %1", ledgerJournalTrans.Voucher));
                    
                }
         
                streamReader.Close();

                ttsbegin;

                    ledgerJournalValidate = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::No);
                    
                    if (ledgerJournalTable.numOfLines() > 0)
                    {
                        ledgerJournalValidate.runOperation();

                        if (!ledgerJournalValidate.tableErrorLog())
                        {
                            ledgerJournalPost = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes);
                            ledgerJournalPost.runOperation();

                        }
                        else
                        {
                            Error(@"errorLog : %1",ledgerJournalValidate.tableErrorLog());

                        }
                    }
                    else
                    {
                        Error(@"CannotPostJournal");
                    }
             
                ttscommit;

            }
            
            else
            {
                Error(@"Failed to create streamReader object for Reading.");
            }

          }
            
        }

        catch(Exception::CLRError)
        {
            throw error(@"An error occurred while creating the StreamWriter/StreamReader object for writing/Reading.");
        }

        finally
        {
            CodeAccessPermission::revertAssert();
        }
        
    }

}

this image containing the exact errors:

errors: Account Number must be Specified & Voucher not specified as of 4/6/2023

& this is how my input text file look like :

Text File

Thanks & Regards,

Harshit

I have the same question (0)
  • Suggested answer
    Komi Siabi Profile Picture
    13,190 Most Valuable Professional on at

    Hello, 

    For the voucher, you can get the voucher from the journalname.

    voucher =  NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable)).voucher();
    ledgerJournalTrans.Voucher = voucher;

    Every journal is made of a main and an offset account. Nowhere in your code where you are passing that the main account.

  • Harshit Tyagi Profile Picture
    63 on at

    Hi Komi,

    I have tried your way for generating Number Sequence but its throwing error : Number Sequence 0 does not exist.

    The code I used before for creating Number Sequence is generating some number sequence but at the time of inserting the value into Voucher field in LedgerJournalTrans Table, It shows null.

    Also, I am bit confused how to give this main Account based on Account Type- Ledger, I mean what's that field which stores the main Account value initially. Can you please more elaborate on this.

    Thanks & Regards,

    Harshit 

  • Suggested answer
    Komi Siabi Profile Picture
    13,190 Most Valuable Professional on at

    Hello Harshit,

    That's because you are NOT specifying the right JournalName.

    Line 33.  ledgerJournalTable.JournalName = @"GL Batch Journal";  - Does this return any journal ID at all?

    [quote user="Harshit Singh"]

    Also, I am bit confused how to give this main Account based on Account Type- Ledger, I mean what's that field which stores the main Account value initially. Can you please more elaborate on this.

    [/quote]

    Check the following thread and edit where applicable.

    community.dynamics.com/.../create-ledger-journal-by-code-x

  • Harshit Tyagi Profile Picture
    63 on at

    Hi Komi,

    Thanks for the reply.

    yes, you are right their is no journal ID associated with the journal Name- "GL Batch Journal", But now I have created a journal Name- GLBatchJou & choose a voucher series from dropdown but still get this error : Number Sequence 0 does not exist. 

    I have used the same code as you told: 

    Voucher voucherNum;

    voucherNum =  NumberSeq::newGetVoucherFromId((ledgerJournalName.NumberSequenceTable)).voucher();

    ledgerJournalTrans.Voucher = voucherNum;

    JournalName.png

    Also, I have used existing Journal Names-'GenJrn'  in my system which have used in some Transactions but still getting this error.

    newJournalname.png

    Also, As you gave a reference to get the ledger Dimension, I have used that code as :

     ledgerJournalTrans.AccountType       = LedgerJournalACType::Ledger;

    ledgerJournalTrans.TransactionType = LedgerTransType::GeneralJournal;
    ledgerJournalTrans.LedgerDimension = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(ledgerJournalTrans.JournalNum,LedgerJournalACType::Ledger);

    I didn't get anything while using this code then I debug and got this exception on third line (LedgerDynamicAccountHelper)  : symbols not loaded for Dynamics.AX.ApplicationPlatform.0.netmodule.

    Thanks & Regards,

    Harshit

  • Suggested answer
    Komi Siabi Profile Picture
    13,190 Most Valuable Professional on at

    Hello Harshit Singh,

    Based on the txt file you uploaded, I can not find ledger account(s) anywhere. That is why the ledger Dimension does not have any value.

  • Harshit Tyagi Profile Picture
    63 on at

    Hi Komi,

    Thanks for the reply.

    The voucher issue gets resolved now.

    As you said, I will add one more row in text file for getting main/Ledger Account, let say, 110112, but the Account Structure for LedgerJournalACType::Ledger is something like this - MainAccount-BusinessUnit-Department, if I get Main Account from my text file & Business unit & department values related to the Journal Name which I used. Then my question is How to merge them to populate the Account field on lines.

    Same thing for my offset Account if LedgerJournalACType::Bank then how can get its value bcz all these account related to Ledger Dimension & offset Ledger Dimension which is a reference for these accounts.

    Account.png

    Thanks & Regards,

    Harshit

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 545 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 408

#3
Adis Profile Picture

Adis 267 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans