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 :
Microsoft Dynamics AX (Archived)

Create project journal

(0) ShareShare
ReportReport
Posted on by 327

Hello,

When I use the following code from the cookbook to create project hour journal,

static void ProjJournalCreate(Args _args)
{
        ProjJournalTable jourTable;
        ProjJournalTrans jourTrans;
        ProjJournalTableData jourTableData;
        ProjJournalTransData jourTransData;
        ProjJournalStatic jourStatic;
        ttsBegin;
        jourTableData = JournalTableData::newTable(jourTable);
        jourTable.JournalId = jourTableData.nextJournalId();
        jourTable.JournalType = ProjJournalType::Revenue;
        jourTable.JournalNameId = 'PrjExp';
        jourTableData.initFromJournalName(ProjJournalName::find(jourTable.JournalNameId));
        jourStatic = jourTableData.journalStatic();
        jourTransData = jourStatic.newJournalTransData(jourTrans, jourTableData);
        jourTransData.initFromJournalTable();
        jourTrans.initValue();
        jourTrans.ProjId = 'ProjID-00001-01';
        jourTrans.initFromProjTable(ProjTable::find(jourTrans.ProjId));
        jourTrans.TransDate = systemDateGet();
        jourTrans.ProjTransDate = jourTrans.TransDate;
        jourTrans.CategoryId = 'Re-Army - Fees';
        jourTrans.setHourCostPrice();
        jourTrans.setHourSalesPrice();
        jourTrans.TaxItemGroupId = ProjCategory::find(jourTrans.CategoryId).TaxItemGroupId;
        jourTrans.Worker = DirPersonUser::currentWorker();
        jourTrans.Txt = 'Design documentation';
        jourTrans.Qty = 8;
        jourTransData.create();
        jourTable.insert();
        ttsCommit;
        info(strFmt("Journal '%1' has been created", jourTable.JournalId));
}


I get the following error

ej.png

Any help is most appreciated.

Thanks in advance.

*This post is locked for comments

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

    Hi J. Doe,

    Do you get the same error when you create the journal manually? Have you checked the number sequence setup for project journals in the project parameters? Does the journal name 'PrjExp' exists as project journal name with the revenue type? The abbreviation 'Exp' is usually used for expenses. So, is your setup matching the hardcoded values?

  • NewWatermelon Profile Picture
    327 on at

    I don't get the same error when I create the journal manually.

    Yes, the journal name 'PrjExp' exist but I don't how to express the expense type instead of revenue type.

    I don't find a value in the ProjJournalType enum expressing expense.

  • NewWatermelon Profile Picture
    327 on at

    My target is to create project expense journal.

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

    Hi,

    Thanks for your feedback. I think we found the culprit now. The expense type is not a project journal, but a ledger journal. You have to use the LedgerJournalTable, LedgerJournalTrans and LedgerJournalTrans_Project tables for creating expense journals.

  • NewWatermelon Profile Picture
    327 on at

    Now I use this job

    static void ProjJournalCreate(Args _args)
    {
        LedgerJournalTable jourTable;
        LedgerJournalTrans jourTrans;
        LedgerJournalTrans_Project  jourTrans_Project;
        LedgerJournalTableData jourTableData;
        LedgerJournalTransData jourTransData;
        LedgerJournalStatic jourStatic;
        ttsBegin;
        jourTableData = JournalTableData::newTable(jourTable);
        jourTable.JournalNum = jourTableData.nextJournalId();
        jourTable.JournalType = LedgerJournalType::Cost;
        jourTable.JournalName = 'PrjExp';
        jourTableData.initFromJournalName(LedgerJournalName::find(jourTable.JournalName));
        jourStatic = jourTableData.journalStatic();
        jourTransData = jourStatic.newJournalTransData(jourTrans,jourTableData);
        jourTransData.initFromJournalTable();
        jourTrans.initValue();
        jourTrans_Project.ProjId = 'ProjID-00001-01';
        jourTrans.TransDate = systemDateGet();
        jourTrans_Project.CategoryId = 'Re-Army - Fees';
        jourTrans_Project.CostPrice = 70;
        jourTrans_Project.Qty = 8;
        jourTable.insert();
        jourTransData.create();
        jourTrans_Project.RefRecId = jourTrans.RecId;
        jourTrans_Project.insert();
        ttsCommit;
        info(strFmt("Journal '%1' has been created", jourTable.JournalNum));
    }
    


    and I get this error

    0624.ej.png

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

    Hi,

    Not sure, but you are doing a jourTable.insert() quite late. I would first finalize the table before doing steps for the lines. Have you used the debugger to see more information about filled table fields and variables?

  • NewWatermelon Profile Picture
    327 on at

    I changed the LedgerJournalTable.insert() now like this

    static void ProjJournalCreate(Args _args)
    {
        LedgerJournalTable jourTable;
        LedgerJournalTrans jourTrans;
        LedgerJournalTrans_Project  jourTrans_Project;
        LedgerJournalTableData jourTableData;
        LedgerJournalTransData jourTransData;
        LedgerJournalStatic jourStatic;
        ttsBegin;
        jourTableData = JournalTableData::newTable(jourTable);
        jourTable.JournalNum = jourTableData.nextJournalId();
        jourTable.JournalType = LedgerJournalType::Cost;
        jourTable.JournalName = 'PrjExp';
        jourTableData.initFromJournalName(LedgerJournalName::find(jourTable.JournalName));
        jourTable.insert();
        
        jourStatic = jourTableData.journalStatic();
        jourTransData = jourStatic.newJournalTransData(jourTrans,jourTableData);
        jourTransData.initFromJournalTable();
        jourTrans.initValue();
        jourTrans_Project.ProjId = 'ProjID-00001-01';
        jourTrans.TransDate = systemDateGet();
        jourTrans_Project.CategoryId = 'Re-Army - Fees';
        jourTrans_Project.CostPrice = 70;
        jourTrans_Project.Qty = 8;    
        jourTransData.create();
        jourTrans_Project.RefRecId = jourTrans.RecId;
        jourTrans_Project.insert();
        ttsCommit;
        info(strFmt("Journal '%1' has been created", jourTable.JournalNum));
    }


    and I still get the same error from this line 

    if (journalTableData.journalVoucherNum() && journalTableData.journalTable().VoucherDraw == JournalVoucherDraw::Entering)

    from this method

    public void create(
        boolean _doInsert           = false,
        boolean _initVoucherList    = true)     // automatic JournalTrans add in voucherList. False if adding all transactions yourself -> better performance
    {
        lastLineNum++;
    
        journalTrans.LineNum  = lastLineNum;
    
        if (journalTableData.journalVoucherNum() && journalTableData.journalTable().VoucherDraw == JournalVoucherDraw::Entering)
        {
            this.initVoucher(lastVoucher,false,_initVoucherList);
        }
    
        this.addTotal(false, false);
    
        if (_doInsert)
        {
            journalTrans.doInsert();
        }
        else
        {
            journalTrans.insert();
        }
    
        if (journalTableData.journalVoucherNum())
        {
            lastVoucher = journalTrans.Voucher;
        }
    }


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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans