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.

Sunday, 20 April 2014

How to increase the performance of crm form

Hello CRM Lovers,
         
   Many times we see that crm form takes much time to load, this is really hectic. Every one wants smooth processing of crm. So we have to take care of the thing by which crm perform well.

  Slow processing may be due to fallowing reasons, slow internet, less ram and java scripts on crm form. Improper java scripts code is also a bigger reason for slow processing of crm form.

  In this post of mine I am going to describe about best practices for use of java script code.

These are some things you should remember before using java script on crm form.

1. Do not include unnecessary java script web resource library :-

As we know if any web page contains more script to include on page load, page will take more time to load, so the more scripts you add to the form, the more time it will take to download them. After loading first time scripts get cached in browser. But as we usually say first impression is the last impression, so we have to try to not include unnecessary web resource library on crm form.

For a example, don’t include jQuery in your form scripts simply because if you want to use XMLHttpRequests. While jQuery has the $.ajax function that many people are familiar with to perform these requests, it is a developer preference, not a necessity. It is possible and better also to perform these requests using the native XMLHttpRequest object found in all browsers supported by Microsoft Dynamics CRM.

2. Try to avoid loading all scripts in the Onload eventof the crm form :-

If you have code that only supports OnChange events for fields or the OnSave event, make sure to set the script library with the event handler for those events instead of the OnLoad event. This way loading those libraries can be deferred and increase performance when the form loads. We do not recommend using the addOnChange method within the OnLoad event handler simply as a matter of convenience. While this may reduce the number of steps necessary to add your event handlers, it causes the form to load more slowly.

3. Use collapsed tabs to defer loading web resources :-

Here is one intresting thing whenever a web resources or IFRAMES are included in sections inside a collapsed tab, they will not be loaded if the tab is collapsed so the script will also not get loded on page load. They will be loaded when the tab is expanded. When the tab state changes, the TabStateChange event occurs. Any code that is required to support web resources or IFRAMEs within collapsed tabs can use event handlers for the TabStateChange event and reduce code that might otherwise have to occur in the OnLoad event. So we we have to think and decide which code should written on Onload event of the crm form.

4. Try to set default visibility options :-

We have to use default functionality for hiding attributes, We should avoid to use form scripts in the OnLoad event to hide form elements. Instead, set the default visibility options for form elements that might be hidden to not be visible by default when the form loads. Then, use scripts in the OnLoad event to show those form elements you want to display.

Enjoy the great technology Dynamics CRM. Good luck.

Saturday, 19 April 2014

How to filter lookup in crm 2013


How filter lookup in CRM 2013.

Hello CRM Lovers,
         
   After release of CRM 2013 we got many new features in CRM. First is that performance increases of crm. There are various changes in java script functions for increasing performance of crm.

   Here is my new post with the new java scripts in crm 2013 for filtering lookup. In CRM 2013 there are many new functions for filtering like prefilter, removePrefilter etc. In this post I am going to describe how to use these functions.These functions will also increase performance of crm form.

Here is all about new lookup controls,s methos and events :- 

1. Method : addCustomFilter()  :-  

This function is new in crm 2013. It works as an additional filter to result displayed in lookup dialog each previous filter added with an AND condition to display result in lookup dialog. 

Note :-  
  • This method is only available for updated entities in crm 2013.
  • This method can only be used in a function in an event handler for the Lookup Control PreSearch Event.
 

         
    addCustomFilter();
     
      Xrm.Page.getControl("attributename").addCustomFilter(filter, entityLogicaName);
      
      Here filter is fetch xml for results and entityLogicalName 
      is name of the entity. 
      Example :-         
             <filter type="and">
               <condition attribute="name" operator="eq" value="Test" />
             </filter>

2. How to add custom view on lookup control :- 

Method : addCustomView():- This method is used to add custom view on  the lookup control.

Note :- This method does not work on "Owner" lookup. 


    addCustomView(); 
   
      Xrm.Page.getControl("attributename").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);

    Where :-
            viewId :- unique guid of format “{00000000-0000-0000-0000-000000000001}”.
    entityName :- Name of the entity of type "string".
    viewDisplayName :- Name of the view(Your custom name)of type "string".
    fetchXml :- fetch for retrieve data of type "string".
    layoutXml :- layout xml is for showing the records in a format as you want of type "string".
    isDefault :- Do you want this view as default of type "bool".

  

3. How to get default view of CRM lookup control :-


    
    getDefaultView();
       
      var attrParent = Xrm.Page.getControl("attributename").getDefaultView();

    Returns the Id of the default view of the lookup dialog in 
    string.

4. How to set default view of CRM lookup control :-


       
    setDefaultView();
       
      Xrm.Page.getControl("attributename").setDefaultView(viewGuid);

              Where :-
      viewGuid :- Guid of the view.
          Set,s the default view in lookup dialog .


5. How to add or remove lookup control PreSearchEvent :-    

         This is new functionality in CRM 2013. Lookup PreSearchEvent just occurs just before the lookup dialog opens. Like other form and control events crm form editor does not peovide a way to add PresSerachEvent.This event can be used with other lookup methods like addCustomView, addCustomFilter etc.

Note :- These events only available for all custom entities in crm 2013 and these system entities :- Account,  Appointment, Campaign, Campaign Activity,Campaign Response,Case,Competitor,Contact,  Contract,Contract Line,Email,Fax,Invoice,Lead,Letter,Marketing List,Opportunity,Opportunity,  Product,Order,Phone Call,Price List Item,Product,Quick Campaign,Quote,Recurring Appointment, Sales Literature,Team,Task,User. 


    addPreSearch();
    
             Xrm.Page.getControl("attributename").addPreSearch(functionName);
      
      Where :-      
      functionName:- is the name of the function which you want to 
                     call before lookup, launch dialog.
    removePreSearch();

      Xrm.Page.getControl("attributename").removePreSearch(functionName);
       
      Where :-      
      functionName:- is the name of the function which you want to remove.

Enjoy the great technology Dynamics CRM. Good luck.

Saturday, 12 April 2014

New java script functions in CRM 2013


New java script functions for CRM 2013.

Hello CRM Lovers,
          Here is my new post with the new java scripts for crm 2013. This post is all about how to change display behavior of crm controls at client side.

   We access any control on crm from with these objects Xrm.Page.ui.controls, Xrm.Page.uiSection.controls, or Xrm.Page.data.entityAttribute.controls. The Xrm.Page.getControl may be accessed by Xrm.Page.ui.controls.get
    In this post I am goint to tell you how to use Xrm.Page.getControl method to access a control. Which control depends on the arguments passed to the method.

   Whenever a form displays or loads in crm 2013 a business process flow control in the header, additional controls will be added for each attribute that is displayed in the business process flow. These controls have a unique name like the following: header_process_<attributename>.
Controls displayed in the form header are accessible and have a unique name like the following: header_<attributename>.

1. How to get type of a CRM attribute  :-


         
    getControlType();
     
      var attrType = Xrm.Page.getControl("attributename").getControlType();
    
    Return type will be string. returned values may be standard,optionset,lookup,
    subgrid,notes,webresource,iframe,lookup.

2. How to get name of crm attribute :-



    getName(); 
   
      var attrName = Xrm.Page.getControl("attributename").getName();

            Returns the name assigned to the attribute.   

3. How to get parent of crm attribute :-


    
    getParent();
       
      var attrParent = Xrm.Page.getControl("attributename").getParent();

    Returns the object of the parent control or section in which 
    current control resides.

4. How to get and change label of CRM attribute :-


       
    getLabel();       

         var attrLabel = Xrm.Page.getControl("attributename").getLabel();

    setLabel();
         var attrLabel = Xrm.Page.getControl("attributename").setLabel("labelname");

5. How to display or remove notification about the CRM attribute :-    

         setNotification method displays a message nearby the attribute to indicate that data entered in the attribute is not valid . Whenever this method is used on Microsoft Dynamics CRM for tablets a red "X" icon appears next to the attribute. On tapping on the icon message will display. 

Note :- setNotification and clearNotification methods only available for all custom entities and these system entities :- Account,  Appointment, Campaign, Campaign Activity,Campaign Response,Case,Competitor,Contact,  Contract,Contract Line,Email,Fax,Invoice,Lead,Letter,Marketing List,Opportunity,Opportunity,  Product,Order,Phone Call,Price List Item,Product,Quick Campaign,Quote,Recurring Appointment, Sales Literature,Team,Task,User. 


    setNotification();
    
             Xrm.Page.getControl("attributename").setNotification("message","uniqueid");
      //type of uniqueid should be string, it is just used to 
        remove notification. Returns type of bool.
   
    clearNotification();

      Xrm.Page.getControl("attributename").setNotification("uniqueid");     
      //Returns type of bool.

Enjoy the great technology Dynamics CRM. Good luck.

Monday, 31 March 2014

CRM 2013 basic java scripts

.

Basic Java Script for CRM 2011 and CRM 2013?

Hello CRM Lovers,
          Here is my new post with the basic java scripts for crm 2011 and as well as for crm 2013.


1. How to get and set CRM form attribute value :- 

Note :- Controls that are not bound to an attribute (subgrid, web resource, and IFRAME) do not have this method. An error will be thrown if you attempt to use this method on one of these controls.


        
     //Get Object of attribute :- 
      var attr  =  Xrm.Page.getAttribute("attributename");

    //Get attribute value :- 
      var attr  =  Xrm.Page.getAttribute("attributename").getValue();

    //Set attribute value :-  
      var attr  =  Xrm.Page.getAttribute("attributename").setValue("Value of attrubute type");

 

2. How to set visibility of crm attribute :-



    //Set Visible True :-   
      Xrm.Page.ui.controls.get("attributename").setVisible(true);

    //Set Visible False :-   
      Xrm.Page.ui.controls.get("attributename").setVisible(false);

3. How to enable disable crm attribute :-


    //Returns whether the control is disabled :-
      Xrm.Page.getControl("attributename").getDisabled();

        //Set Read Only :-
      Xrm.Page.getControl("attributename").setDisabled(true);

    //Set Enable True :-
      Xrm.Page.getControl("
attributename").setDisabled(
false);

4. How to set focus CRM attribute :-



        //Set Focus True :-
      Xrm.Page.getControl("attributename").setFocus(true);

    //Set Focus False :-
      Xrm.Page.getControl("
attributename").setFocus(
false);

5. How to show hide CRM form tab :-


    
    //Show CRM Tab :-
             Xrm.Page.ui.tabs.get("tabname").setVisible(true);

    //Show CRM Tab :-
            Xrm.Page.ui.tabs.get("tabname").setVisible(false);

Thursday, 27 February 2014

Pass custom query string parameter in CRM 2013

  Pass custom query string parameter in CRM 2013.

Hello CRM Developers,
          This is my new post in which I am going to describe how to pass custom query string parameter in crm2013.

It is a very good feature of query string parameter in MS CRM. But we have to take care of use it because query string parameter will be visible to end user, so you should not pass confidential info in query string.

By default MS CRM allows a set of query string parameters to be passed to a crm form, these parameter must use a standard naming convention.

For detailed information you can fallow this link.

http://msdn.microsoft.com/en-us/library/gg334375.aspx 


There may be requirement of pass custom query string parameter in your crm2013 application. in this post I am going to tell you how to pass custom parameter of different data types.

Step 1:- Go to Settings=> Customizations => Customize The System
              => Entities=>Your Entity=>Forms and Fallow steps as shown in
              image.

 

Step 2:-  Now add the following java script code in your crm 2013 web 
               resource.


window.open(Xrm.Page.context.getServerUrl() +"/main.aspx?etn=account
&extraqs=parameter_0=test&pagetype=entityrecord");

//To Access the  query string parameter on target use the following code

var parameters = Xrm.Page.context.getQueryStringParameters();
var ParameterValue= parameters ["parameter_0"];




 

Note : -   Remember one importent thing your parameter should add just after
              the "extraqs". Like "main.aspx?etn=contact&extraqs=param_1=test&
              pagetype=entityrecord”.

              For more information you can visit the fallowing link.

              http://msdn.microsoft.com/en-us/library/gg334436.aspx 

              http://msdn.microsoft.com/en-us/library/gg328131.aspx 

For further help you can leave a comment.

Enkoy the great technology Dynamics CRM. Good Luck .....!!!!
Thanks