Translate

Sunday 27 July 2014

current fiscal year in crm 2013


How to get current fiscal year in CRM 2013.

Hello CRM Lovers,
         
   Here is my new post, In this post you can get current fiscal year according to the settings in CRM.

   There is no as such function in CRM 2011 nor in CRM 2013 which can retrieve current fiscal year directly. we need to write our custom function in java script or in plugin or in custom workflow for getting current fiscal year.

Below is the procedure for getting current fiscal year in CRM.

Step 1:- The first step is that you have to retrieve "fiscalyearstart" (Fiscal year start date from "organization" entity).

Now use this function to calculate current fiscal year.

 Function for plugin or custom workflow.

         
    public int getCurrentFiscalYear(DateTime fiscalcalendarstartdate)
        {
            int currentFiscalYear;

            //fiscalcalendarstart is date which you have to retrieve from organization entity
            DateTime sDate =
fiscalcalendarstartdate;
           
DateTime currentDate = System.DateTime.Now;

            if (sDate < currentDate)
            {
                int diff = currentDate.Year - sDate.Year;
                currentFiscalYear = sDate.Year + diff;
            }
            else
            {
                int diff = sDate.Year - currentDate.Year;
                if (diff == 0)
                    currentFiscalYear = sDate.Year + 1;

                else
                    currentFiscalYear = sDate.Year - diff;
            }

            return currentFiscalYear
        }




 Function for java script.

function getCurrentFiscalYear(fiscalcalendarstart) {
   
var CurrentFiscalYear;
   
//fiscalcalendarstart is date which you have to retrieve from organization entity  //Organisation Fiscal start date
    var sDate = new Date(fiscalcalendarstart);
   
var today = new Date();
         var todayDate = today.getMonth() + 1 + "/" + today.getDate() + "/" + today.getFullYear();
   
var currentDate = new Date(todayDate);

    if (startDate <= todayDate) {

       
var diff = currentDate.getFullYear() - sDate.getFullYear();

       
CurrentFiscalYear = (parseInt(sDate.getFullYear()) + parseInt(diff));

    }
    else {

       
var diff = sDate.getFullYear() - currentDate.getFullYear();

        if (parseInt(diff) == 0) {

           
CurrentFiscalYear = (parseInt(sDate.getFullYear()) - parseInt(1));

        }
        else {
           
CurrentFiscalYear = (parseInt(sDate.getFullYear()) - parseInt(diff));
        }
    }
}

For details visit this post.
http://crmjavascripts.blogspot.com/2013/06/current-fiscal-year-in-crm-2011.html


Enjoy the great technology Dynamics CRM.