Skip to main content

Notifications

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

Getting Errors while Posting a General Journal against a Fixed-Price project

(0) ShareShare
ReportReport
Posted on by 47

Hi,

I am getting errors while Posting a general Journal against Project. I have created a class which is then creating Journal & posting it.

I am calling this class in OnInsert event Handler of ProjTable.

This is the Class which creating & Posting Journal:

class HSHTCreateJournal
{
    LedgerJournalTable         ledgerJournalTable;
    LedgerJournalTrans         ledgerJournalTrans;
    ProjTable                  projTable;
    JournalTableData           journalTableData;
    LedgerJournalName          ledgerJournalName;
    LedgerJournalCheckPost     ledgerJournalValidate, ledgerJournalPost;
    Voucher                    voucherNum;
    Amount                     amount = 10000;

    public void createProjectJournal(ProjId _projId)
    {
        ledgerJournalTable.initvalue();
        journalTableData = JournalTableData::newTable(ledgerJournalTable);
        ledgerJournalTable.JournalType = LedgerJournalType::Cost;
        ledgerJournalTable.JournalNum = journalTableData.nextJournalId();
        ledgerJournalTable.JournalName = @"GLRevenue";
        ledgerJournalTable.initFromLedgerJournalName();
        ledgerJournalTable.initFromLedgerJournalTable(ledgerJournalTable);
        ledgerJournalTable.VoucherAllocatedAtPosting = NoYes::Yes;
        ttsbegin;
        if (ledgerJournalTable.validateWrite())
        {
            ledgerJournalTable.insert();
            Info("Journal Header created");
        }
        ttscommit;

        Info(strFmt("Journal Num: %1",ledgerJournalTable.JournalNum));
        ledgerJournalName = LedgerJournalName::find(ledgerJournalTable.JournalName);
        voucherNum =  NumberSeq::newGetVoucherFromId((ledgerJournalName.NumberSequenceTable)).voucher();

        select firstonly projTable
            where projTable.ProjId == _projId;
        Info(strFmt("Project Id: %1, project Name : %2",projTable.ProjId,projTable.Name));
        if (ledgerJournalTable)
        {
            ledgerJournalTrans.clear();
            ledgerJournalTrans.initValue();
            ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
            ledgerJournalTrans.Voucher    = voucherNum;
            ledgerJournalTrans.TransDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
            ledgerJournalTrans.Qty = 1;
            ledgerJournalTrans.AccountType = LedgerJournalACType::Project;
            ledgerJournalTrans.TransactionType   = LedgerTransType::Project;
            ledgerJournalTrans.LedgerDimension = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(projTable.ProjId,LedgerJournalACType::Project);
            ledgerjournalTrans.OffsetAccountType = LedgerJournalACType::Bank;
            ledgerJournalTrans.CurrencyCode = @'USD';
            ledgerJournalTrans.Txt = strFmt("Expense Journal");
            ledgerJournalTrans.Approved = NoYes::Yes;
            if(amount> 0)
            {
                ledgerJournalTrans.AmountCurDebit = amount;
            }
            else
            {
                ledgerJournalTrans.AmountCurCredit = abs(amount);
            }
            ledgerJournalTrans.Company = strUpr(curExt());
            ledgerJournalTrans.OffsetCompany = strUpr(curExt());

            //Validate and insert the journal line
            ttsbegin;

            if (ledgerJournalTrans.validateWrite())
            {
                ledgerJournalTrans.insert();
                Info("Journal Lines inserted");
            }
                          
            else
            {
                throw Exception::Error;
            }
                            
            ttscommit;
            
        }
        
        ttsbegin;
        // Posting the journal
        ledgerJournalValidate = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::No);
        if (ledgerJournalTable.numOfLines() > 0)
        {
            ledgerJournalValidate.runOperation();
                    
            if (!ledgerJournalValidate.tableErrorLog())
            {
                ledgerJournalPost = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes);
                ledgerJournalPost.runOperation();
                Info("Journal posted Succesfully");
            }
                    
            else
            {
                Error(@"errorLog : %1",ledgerJournalValidate.tableErrorLog());
            }
        }

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

This is the OnInsert Event Handler in which I am creating above class Instance: 

class HSHTProjTableHandler
{  
    /// 
    ///
    /// 
    /// 
    /// 
    [DataEventHandler(tableStr(ProjTable), DataEventType::Inserted)]
    public static void ProjTable_onInserted(Common sender, DataEventArgs e)
    {
        ProjTable projTable = sender as ProjTable;
        Info(strFmt("project created successfully with Project Id : %1 & Project InvoiceId : %2 ",projTable.ProjId,projTable.ProjInvoiceProjId));

        HSHTCreateJournal createJournal = new HSHTCreateJournal();
       
        if (projTable.Type == ProjType::FixedPrice)
        {           
            ttsbegin;
            projTable.Status = ProjStatus::Completed;
            projTable.update();
            ttscommit;
            createJournal.createProjectJournal(projTable.ProjId);
            
        }
        
    }

}

Errors:

GLJournal.png

  • Harshit Singh Profile Picture
    Harshit Singh 47 on at
    RE: Getting Errors while Posting a General Journal against a Fixed-Price project

    Hi Mohit,

    I got the solution, actually I forgot to Initialized LedgerJournalTrans_Project table fields. 

    I took reference from link below & the link you shared as well.

    https://community.dynamics.com/365/financeandoperations/b/nareshsdynamicsaxblog/posts/d365-ax7-create-and-post-project-expense-journals

    Thanks,

    Harshit

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: Getting Errors while Posting a General Journal against a Fixed-Price project

    Hi Harshit,  CurrencyCode is incorrectly mapped to @'USD', please use "USD" instead in Line#49. I believe you are getting this error during Journal creation, add the missing fields.

    Check this old thread and article for reference

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

    community.dynamics.com/.../create-ledger-journals-in-d365fo-using-x

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,111 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,934 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans