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.....!!!!! 

Monday, 10 June 2013

How to Convert Option Set in to a Check Box list ?

How to Convert Option Set in to a Check Box list with java script.

Here is my new update, in this blog you can find the process and code to convert option set into a check box list. And one important thing is that it will work on CRM roll-up 11, CRM roll-up 12 and CRM roll-up 13. So just enjoy the great technology like CRM.

Step 1:- First Create option set which you want to convert into Checkbox list.
Step 2:- Create another attribute to store value of option set.
Step 3:- Add both the fields on the entity form.
Step 4:- Create new web resource or update existing web resource with the fallowing code.  

    function Form_onload() {

    var _crtlSociaklNW = document.getElementById("new_socialnetwork");
    var _crtlTextSocial = document.getElementById("new_textsocial");

    if (_crtlSociaklNW != null && _crtlTextSocial != null) { = "none";
        var pdiv = document.createElement('div'); = 'overflow-y:auto; height:100px; border:1px #6699cc solid;          background-color:#ffffff;';
///////////////////// Convert option set to check box//////////////////////
        for (var i = 1; i < _crtlSociaklNW.options.length; i++) {
            var OptionSetItems = _crtlSociaklNW.options[i];
            if (!IsChecked(OptionSetItems.text, _crtlTextSocial)) {
                var addInput = document.createElement('input');
                addInput.type = 'checkbox';
       = 30;
            else {
                var addInput = document.createElement('input');
                addInput.type = 'checkbox';
                addInput.checked = true;
       = 30;

            var addLabel = document.createElement('label');
            addLabel.innerText = OptionSetItems.text;
            var addBr = document.createElement('br');
            var formname = Xrm.Page.getAttribute("new_name").getValue();


///////////////// To check if which check box is selected//////////////////
function IsChecked(pText, _crtlTextSocial) {
    if (_crtlTextSocial.value != "") {
        var _crtlTextSocial = _crtlTextSocial.value.split(",");
        for (var i = 0; i < _crtlTextSocial.length; i++) {
            if (_crtlTextSocial[i] == pText)
                return true;
    return false;
///function to save the selected Items from check box list to TextSocial///
function Form_onSave() {
    var _crtlSociaklNW = document.getElementById("new_socialnetwork");
    var txtSocialValue = "";
    var getInput = _crtlSociaklNW.nextSibling.getElementsByTagName("input");

    for (var i = 0; i < getInput.length; i++) {
        if (getInput[i].checked) {
            txtSocialValue += getInput[i].nextSibling.innerText + ",";


Step 5:- Now call Form_onload() function on Form OnLoad event and Form_onSave() function on             form OnSave event. And then save and publish form.
            Now your form will look like this.
Step 6:- Select check boxes and then save then it will look like this.
Step 7:- Now Hide TextSocial on the entity form.
Step 8:- Now it will look like.
 Soon i will write my new post "How to hide these check boxes on the basis of condition"

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

Thursday, 6 June 2013

How to filter view on dashboard with html web resource.

CRM-2011 How to filter view on dashboard ?

CRM-2011 How to filter view without date time attribute ?    

CRM-2011 How to filter view with HTML web resource ?   

CRM-2011 How to update fetch of a view ?   

CRM-2011 How to filter view on dashboard with HTML web resource ? 

Here you can get the answer of above questions regarding CRM 2011.

If you want to filter a view on the dashboard with date time and you do not have date time attribute and option set of for month and year in your entity then don’t worry you are on right place. I will provide you code and steps by which you can filter view with date time without having date time field in entity related to view. 

Step 1: First of all add a HTML web resource in your crm solution. And write the fallowing code in the                 web resource.

          <title> </title>
               <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
               <script type="text/javascript">
                       function submitForm() {
                            var form = document.forms[0];
                            var context = GetGlobalContext();
                            form.action = context.getServerUrl() + '/AdvancedFind/fetchData.aspx';                           
                            form.LayoutXml.value = '<grid name="resultset" object="10172" jump="atr_name" select="1" icon="1" preview="1"></grid>';
                            form.FetchXml.value = "<fetch version='1.0' mapping='logical'><entity name='Entity Schema Name'><attribute name='atr_xyz' /><attribute name='atr_name' /><attribute name='createdon' /><order attribute='atr_name' descending='false' /><filter type='and'><condition  attribute='atr_year' operator='eq' value='" + new Date().getFullYear() + "' /><condition attribute='atr_systemuserid' operator='eq-userid' /></filter></entity></fetch>";
           <meta charset="utf-8">
    <body onload="submitForm()">
        <form method="post" action="">
           <input name="FetchXml" type="hidden">
           <input name="LayoutXml" type="hidden">
           <input name="EntityName" value="entity svhema name" type="hidden">
           <input name="DefaultAdvFindViewId" value="32 Bit View Id" type="hidden">
           <input name="ViewId" value="00000000-0000-0000-00AA-000010001004" type="hidden">
           <input name="ViewType" value="10172" type="hidden">
           <input name="SortCol" value="atr_name" type="hidden" ;="">
           <input name="UIProvider" type="hidden">
           <input name="DataProvider" type="hidden">

Step 2: Create or Open dashboard to add web resource on dashboard.

Step 3:  Open dashboard and click on the web resource button to select the 
            web resource button you added in step 1.

Step 4:  Select web resource in web resource look up which you created in
            step 1 and then save and publish

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