Dynamics ax 2012 Trial Balance Detail Report Error “The field with ID ‘0’ does not exist in table ‘LedgerTrialBalanceStagingTmp'”

The field with ID ‘0’ does not exist in table ‘LedgerTrialBalanceStagingTmp’

I’ve been trying to open a report in the General Ledger > Reports > Detailed trial balance. In the form, I input a parameter for Ledger account.MainAccount. When I click OK, I got an error:

Error executing code: The field with ID ‘0’ does not exist in table ‘LedgerTrialBalanceStagingTmp’.

Stack trace

(S)ClassesRecordInsertListadd
(S)ClassesLedgerTrialBalanceDPpopulateTmpTransDetail – line 100
(S)ClassesLedgerTrialBalanceDPprocessReportDetail – line 28
(S)ClassesLedgerTrialBalanceDPprocessReport – line 32
(S)ClassesSrsReportRunRdpPreProcessServiceexecuteWithContract – line 102
(S)ClassesSrsReportRunRdpPreProcessServiceexecuteRDLClasses – line 38
(C)ClassesSrsReportRunServicepreRunReport – line 26
(C)ClassesSrsReportRunImplpreRunReport – line 12
(C)ClassesSrsReportRunController unReport – line 42
(C)ClassesSrsReportRunController un
(C)ClassesSysOperationControllerstartOperation – line 10
(C)ClassesSrsReportRunControllerstartOperation
(C)ClassesLedgerTrialBalanceControllermain – line 9

I was using MS Dynamics AX 2012 R2

SOLUTION:
Need to change the RecordInsertList initialization:
\Classes\LedgerTrialBalanceDP\populateTmpTransDetail, Line 64:

Original line:
recordInsertList = new RecordInsertList(tableNum(LedgerTrialBalanceTmp), true, true, true, true, true, _ledgerTrialBalanceStagingTmp);

Change to:
recordInsertList = new RecordInsertList(tableNum(LedgerTrialBalanceStagingTmp), true, true, true, true, true, _ledgerTrialBalanceStagingTmp);

Compile forward, generate incremental CIL, and it’s done.

Creating a Word document with repeating in Dynamics ax 2012

In this recipe, we will create a Word document with repeating elements. For this demonstration, we will display the contents of the LedgerParameters table in a dynamically generated Word table
we need to prepare a new Word template and save it as a file named table.dotx. The template should contain one bookmark named TableName at the top, and one table beneath with a single row and two columns, as follows:
w2

In the AOT, create a new job named CreateWordTable with the following code:
static void CreateWordTable(Args _args)
{
TableId tableId;
COM word;
COM documents;
COM document;
COM bookmarks;
COM bookmark;
COM tables;
COM table;
COM rows;
COM row;
COM cells;
COM cell;
COM range;
Query query;
QueryRun queryRun;
Common common;
TmpSysTableField fields;
DictField dictField;
int i;
void processBookmark(str _name, str _value)
{
if (!bookmarks.exists(_name))
{
return;
}
bookmark = bookmarks.item(_name);
range = bookmark.range();
range.insertAfter(_value);
}
#define.Word(‘Word.Application’)
#define.template(@’C:\temp\table.dotx’);
tableId = tableNum(LedgerParameters);
try
{
word = new COM(#Word);
}
catch (Exception::Internal)
{
if (word == null)
{
throw error(“Microsoft Word is not installed”);
}
}
documents = word.documents();
document = documents.add(#template);
bookmarks = document.bookmarks();
processBookmark(
‘TableName’,
tableId2pname(tableId));
tables = document.tables();
table = tables.Item(1);
rows = table.rows();
query = new Query();
query.addDataSource(tableId);
queryRun = new QueryRun(query);
queryRun.next();
common = queryRun.get(tableId);
fields = TmpSysTableField::findTableFields(
null, tableId);
while select fields
{
dictField = new DictField(
tableId,
fields.FieldId);
if (dictField.isSystem())
{
continue;
}
i++;
row = rows.item(i);
cells = row.cells();
cell = cells.item(1);
range = cell.range();
range.insertAfter(fields.FieldLabel);
cell = cells.item(2);
range = cell.range();
range.insertAfter(
strFmt(‘%1’, common.(fields.FieldId)));
row = rows.add();
}
row.delete();
word.visible(true);
}

2. Run the job to generate the document containing a list, the LedgerParameters table
field, and their values:

w23

Number of months between two dates in Dynamics ax 2012

Recently I got a situation where I need to calculate the number of months between 2 dates, I found a built in method in dynamics ax 2012 that can be used.

noOfIntervals = intvNo(refDate, inputDate, intvScale::Month);

intvScale enumation have two values for months
â—¾Month
â—¾YearMonth

If we provide the intvScale::Month then X++ ignores the year and assumes that month is calculated within one year.

If we provide the intvScale::YearMonth then X++ calculate the number of months between different years. Consider following example.

There is another way to Calculates the difference between two dates in month units in Dynamics ax 2012 using method InfAdjValidation_MX::monthDifference(FromDate _fromDate, ToDate _toDate)