Tuesday, November 29, 2016

How to see beginning balance journals from your projects

There is a bug in AX 2012 R2/R3.

Beginning balance journals do not create transactions in ProjJournalTrans table; therefore, they won't be selected via the standard query.

This is a small fix to show beginning balance journals from the projects forms.

In ProjJournalFormTable class we need to redo datasourceLinkActivePre() method as follows:

public void datasourceLinkActivePre()
    QueryBuildDataSource    qbds;
    ProjTable               callerRecord;

    if (formRun                 &&
        formRun.args()          &&
        formRun.args().record() &&
        formRun.args().dataset() == tableNum(ProjTable))
        callerRecord = formRun.args().record() as ProjTable;

        // if this is a beginning balance table we have no transactions in ProjJournalTrans
        // therefore, we need to update the query so that all related journals will be shown.
        if(journalTypeId == 2) // beginning balance
            SysQuery::findOrCreateRange(journalTable_ds.query().dataSourceTable(tableNum(ProjJournalTable)), fieldNum(ProjJournalTable, JournalType)).value(SysQuery::value(ProjJournalType::BegBalance));
            SysQuery::findOrCreateRange(journalTable_ds.query().dataSourceTable(tableNum(ProjJournalTable)), fieldNum(ProjJournalTable, ProjId)).value(SysQuery::value(callerRecord.ProjId));
        // End
            qbds = journalTable_ds.query().dataSourceNo(1).addDataSource(tableNum(ProjJournalTrans));


            qbds.addRange(fieldNum(ProjJournalTrans, ProjId)).value(callerRecord.ProjId);


No comments: