Confessions of a Dynamics NAV / Navision consultant. A blog about my experiences being a Navision consultant and developer. How to Calculate the Current Fiscal Year - Confessions of a Dynamics NAV / Navision Consultant

How to Calculate the Current Fiscal Year

In Navision, there's no function that will give you the fiscal year according to what you've setup on the Accounting Period table. Here's a code that will get the current fiscal year based on the accounting period:

AccountingPeriod is a record variable  to table 50
Date1 and Date2 are date variables

AccountingPeriod.RESET;
AccountingPeriod.SETRANGE("New Fiscal Year",TRUE);
AccountingPeriod."Starting Date" := WORKDATE;
AccountingPeriod.FIND('=<');
Date1 := AccountingPeriod."Starting Date";
IF AccountingPeriod.NEXT = 0 THEN
  Date2 := 12319999D
ELSE
  Date2 := AccountingPeriod."Starting Date" - 1;

Published Oct 5, 2009 14:36 by Alex Chow
Bookmark and Share

Comments

# re: How to Calculate the Current Fiscal Year

Tuesday, October 06, 2009 11:30 AM by Marq

What about the function in Codeunit 1?

FindPeriod(Date1,Date2,FindYear,DateFilterText,Position,Length)

ReadCharacter(' ',DateFilterText,Position,Length);

IF FindYear THEN

 AccountingPeriod.SETRANGE("New Fiscal Year",TRUE)

ELSE

 AccountingPeriod.SETRANGE("New Fiscal Year");

Sign := '';

IF ReadSymbol('+',DateFilterText,Position,Length) THEN

 Sign := '+'

ELSE

 IF ReadSymbol('-',DateFilterText,Position,Length) THEN

   Sign := '-';

IF Sign = '' THEN

 IF ReadNumeral(Numeral,DateFilterText,Position,Length) THEN BEGIN

   IF FindYear THEN

     AccountingPeriod.FINDFIRST

   ELSE BEGIN

     AccountingPeriod.SETRANGE("New Fiscal Year",TRUE);

     AccountingPeriod."Starting Date" := WORKDATE;

     AccountingPeriod.FIND('=<');

     AccountingPeriod.SETRANGE("New Fiscal Year");

   END;

   AccountingPeriod.NEXT(Numeral - 1);

 END ELSE BEGIN

   AccountingPeriod."Starting Date" := WORKDATE;

   AccountingPeriod.FIND('=<');

 END

ELSE BEGIN

 IF NOT ReadNumeral(Numeral,DateFilterText,Position,Length) THEN

   EXIT(Position);

 IF Sign = '-' THEN

   Numeral := -Numeral;

 AccountingPeriod."Starting Date" := WORKDATE;

 AccountingPeriod.FIND('=<');

 AccountingPeriod.NEXT(Numeral);

END;

Date1 := AccountingPeriod."Starting Date";

IF AccountingPeriod.NEXT = 0 THEN

 Date2 := 31129999D

ELSE

 Date2 := AccountingPeriod."Starting Date" - 1;

ReadCharacter(' ',DateFilterText,Position,Length);

IF Position <= Length THEN

 EXIT(Position);

EXIT(0);

# re: How to Calculate the Current Fiscal Year

Tuesday, October 06, 2009 2:01 PM by Erik P. Ernst

And what happened to just entering "Y"?

# re: How to Calculate the Current Fiscal Year

Tuesday, October 06, 2009 6:17 PM by Alex Chow

Mark: Codeunit 1 is too complicated if you just need a simple calculation. I extracted the key areas so users can easily understand what needs to be done.

Erik: Y works on date filters, but if you need to get specific dates using Calcdate function, it won't work.

Leave a Comment

(required) 
(required) 
(optional)
(required)