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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
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 63

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

I have the same question (0)
  • Harshit Tyagi Profile Picture
    63 on at

    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
    12,565 Moderator on at

    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

News and Announcements

Season of Giving Solutions is Here!

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
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 288 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans