Thursday, 13 June 2013

Current fiscal year in crm 2011

How to get current fiscal year in CRM 2011.  

   Here is my new update. In this update of mine you can know how to get current fiscal year in CRM on the basis of CRM fiscal year settings.

   Normally fiscal year starts on 1 April to 31 March, but CRM 2011 provides the feature to set our custom fiscal period because fiscal period may differ organization to organization, so there may be need of custom fiscal period, and if custom fiscal period exist then i am sure there will need of current fiscal year. Unfortunately CRM does not stores current fiscal year, so you have to calculate current fiscal year.So in this blog you can get current fiscal year.

Fallow these steps.

Step 1:-  Click on Settings tab.

Step 2:-  Open fiscal year year setting.

Step 3:-  Set the start date and other setting regarding fiscal year.

Step 4:-  Now write this java script code to get current fiscal year in any  variable, you can write this where you want to use current fiscal year.

function getCurrentFiscalYear() {

    //Get Current Date
    var today = new Date();
    var todayDate = today.getMonth() + 1 + "/" + today.getDate() + "/" + today.getFullYear();

    //For rollup 11
    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
        "<soap:Envelope xmlns:soap=\"\" xmlns:xsi=\"\" xmlns:xsd=\"\">" +
        GenerateAuthenticationHeader() +
        "<soap:Body>" +
        "<RetrieveMultiple xmlns=\"\">" +
        "<query xmlns:q1=\"\" xsi:type=\"q1:QueryExpression\">" +
        "<q1:EntityName>organization</q1:EntityName>" +
            "<q1:ColumnSet xsi:type='q1:ColumnSet'>" +
                "<q1:Attributes>" +
                    "<q1:Attribute>fiscalcalendarstart</q1:Attribute>" +

                "</q1:Attributes>" +
            "</q1:ColumnSet>" +
        "<q1:Distinct>false</q1:Distinct>" +

        "</query></RetrieveMultiple>" +

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

    var result = xmlHttpRequest.responseXML.xml;

    var doc = new ActiveXObject("MSXML2.DOMDocument");
    doc.async = false;

    if (doc.selectSingleNode("//q1:fiscalcalendarstart") != null) {

        var startDate = doc.selectSingleNode("//q1:fiscalcalendarstart").attributes[0].nodeTypedValue

        //Organisation Fiscal start date
        var sDate = new Date(startDate);

        var currentDate = new Date(todayDate);

        if (startDate <= todayDate) {

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

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

            // alert(CurrentFiscalYear);

        else {

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

            if (parseInt(diff) == 0) {

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

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

Enjoy the great technology Dynamics CRM. Good luck.....!!!!! 

No comments: