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 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=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
"<soap:Body>" +
"<RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"<query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" 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>" +
"</soap:Body></soap:Envelope>";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var result = xmlHttpRequest.responseXML.xml;
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.async = false;
doc.loadXML(result);
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));
//alert(CurrentFiscalYear);
}
else {
var CurrentFiscalYear = (parseInt(sDate.getFullYear()) - parseInt(diff));
//alert(CurrentFiscalYear);
}
}
}
}
Enjoy the great technology Dynamics CRM. Good luck.....!!!!!
No comments:
Post a Comment