Hello Everyone,
I am trying to close out a fiscal Period in AX 2012 R2 and getting the following message
"You cannot close the fiscal period Period 12 because it is referenced by open transactions. You must post, delete, or change the transaction date of the open transactions before you can close the fiscal period."
I Have already gone ahead and run the famous Job:
static void LKLGrootboekPeriodeAfsluitingWD(Args _args)
{
AccountingDistribution accountingDistribution;
FiscalCalendar fiscalCalendar;
FiscalCalendarPeriod fiscalCalendarPeriod;
FiscalCalendarPeriod _currentPeriod;
Ledger ledger;
counter teller =0;
counter tellervoor =0;
counter tellerna=0;
;
while select accountingDistribution
{
tellervoor++;
}
select * from _currentPeriod where _currentPeriod.RecId==5637148102; //This is the RecId i get for the peroid 12
if (_currentPeriod)
{
ttsBegin;
while select forUpdate RecId from accountingDistribution
where accountingDistribution.AccountingDate >= _currentPeriod.StartDate &&
accountingDistribution.AccountingDate <= _currentPeriod.EndDate &&
accountingDistribution.AccountingEvent == 0
exists join ledger
where ledger.PrimaryForLegalEntity == accountingDistribution.AccountingLegalEntity
exists join fiscalCalendar
where fiscalCalendar.RecId == ledger.FiscalCalendar
exists join fiscalCalendarPeriod
where fiscalCalendarPeriod.FiscalCalendar == fiscalCalendar.RecId &&
fiscalCalendarPeriod.RecId == _currentPeriod.RecId
{
//Enable the row below to automatically delete the record
AccountingDistribution.doDelete();
teller++;
}
ttscommit;
while select accountingDistribution
{
tellerna++;
}
info(strFmt("Amount of records before the problem record(s) were deleted from table Accountingdistribution: %1",tellervoor));
info(strFmt("Deleted: %1",teller));
info(strFmt("Amount of records after the problem record(s) were deleted in table Accountingdistribution: %1",tellerna));
if(tellervoor-teller==tellerna)
{
info("Check: OK!");
}
else
{
info(strFmt("Check: Error! Before %1 - deleted %2 is not %3 (result after deletion)",tellervoor,teller,tellerna));
}
}
}
The job did not find anything to delete and I cannot seem to find what is causing the period not to close. All the other periods are closed... Please anyone who can share some knowledge on this i would be grateful.