Microsoft > Dynamics Forums > CRM > Activities section of accounts needs its "filter on:" to default be All instead of Next 30 days

Answered Activities section of accounts needs its "filter on:" to default be All instead of Next 30 days

  • Tuesday, January 18, 2011 9:12 AM
     
     

    Hi all

     

    I have a problem where when i edit a account and go to activites I allways have to go to the filter on section and choose all because it is default set to "next 30 days".

     

    I have tried to code this so it would choose All but last code i tried crashed my CRM :)

     

    any help would be apriciated :)

     

    /Casper

Answers

  • Tuesday, January 18, 2011 9:45 AM
     
     Answered Has Code

    You need to write java script code for the same..

    following is full code for the same..put this on Account on Load even and enable event and publish changes and see if this works...

    /**************************************************************
    * Start - Change the default view of a view selection combo box
    **************************************************************/
    SetDefaultView = function(viewCombo, viewName, appGrid) {
    
      /* If the view has already been set, we don't need to do it again. */
      if (viewCombo.value != viewName) {
    
        /* Set the new view */
        viewCombo.value = viewName;
    
        /* Call RefreshGridView to run the code in the DHTML control.
         * Without this call, only the selection in the combo box changes,
         * but not the content of the grid */
        appGrid.RefreshGridView();
      }
    }
    
    
    /**************************************************************
    * Event handler. Called whenever the ready state of the
    * areaActivities changes.
    **************************************************************/
    areaActivitiesFrame_OnReadyStateChange = function() {
    
      /* Waiting until the frame has finished loading */
      if (this.readyState == "complete") {
    
        /* This is the frame we're interested in */
        var frame = document.frames("areaActivitiesFrame");
    
        /* And this is the view combo box */
        var viewCombo = frame.document.getElementById("scheduledend");
    
        /* This is the AppGridFilterContainer control we need to refresh the view */
        var appGrid = frame.document.getElementById("AppGridFilterContainer");
    
        /* The view combo box uses a style sheet that references a HTML
         * control. We have to wait until the htc file is loaded,
         * otherwise the call to FireOnChange in the SetDefaultView
         * method will fail. */
        if (viewCombo.readyState == "complete") {
    
          /* If the control already has finished loading, we can
           * directly set the new view. */
          SetDefaultView(viewCombo, "All", appGrid);
        }
    
        else {
          /* Otherwise we have to register another event handler
          * waiting until all of the include files used by the
          * combo box are loaded as well. */
          viewCombo.onreadystatechange = function() {
            if (this.readyState == "complete") {
              SetDefaultView(this, "All", appGrid);
            }
          }
        }
      }
    }
    
    
    /* Set a new onclick event for the History navigation element
     * This is where we register the onreadystatechange event handler */
    if (document.getElementById('navActivities') != null) {
      document.getElementById('navActivities').onclick = function() {
        loadArea('areaActivities');
        document.frames('areaActivitiesFrame').document.onreadystatechange = areaActivitiesFrame_OnReadyStateChange;
      }
    }
    
    
    /**************************************************************
    * End - Change the default view of a view selection combo box
    **************************************************************/
    
    

    MayankP
    My Blog
    Follow Me on Twitter
    • Proposed As Answer by Faisal Fiaz Tuesday, January 18, 2011 11:54 AM
    • Marked As Answer by CasperDK Wednesday, January 19, 2011 12:34 PM
    •  

All Replies

  • Tuesday, January 18, 2011 9:45 AM
     
     Answered Has Code

    You need to write java script code for the same..

    following is full code for the same..put this on Account on Load even and enable event and publish changes and see if this works...

    /**************************************************************
    * Start - Change the default view of a view selection combo box
    **************************************************************/
    SetDefaultView = function(viewCombo, viewName, appGrid) {
    
      /* If the view has already been set, we don't need to do it again. */
      if (viewCombo.value != viewName) {
    
        /* Set the new view */
        viewCombo.value = viewName;
    
        /* Call RefreshGridView to run the code in the DHTML control.
         * Without this call, only the selection in the combo box changes,
         * but not the content of the grid */
        appGrid.RefreshGridView();
      }
    }
    
    
    /**************************************************************
    * Event handler. Called whenever the ready state of the
    * areaActivities changes.
    **************************************************************/
    areaActivitiesFrame_OnReadyStateChange = function() {
    
      /* Waiting until the frame has finished loading */
      if (this.readyState == "complete") {
    
        /* This is the frame we're interested in */
        var frame = document.frames("areaActivitiesFrame");
    
        /* And this is the view combo box */
        var viewCombo = frame.document.getElementById("scheduledend");
    
        /* This is the AppGridFilterContainer control we need to refresh the view */
        var appGrid = frame.document.getElementById("AppGridFilterContainer");
    
        /* The view combo box uses a style sheet that references a HTML
         * control. We have to wait until the htc file is loaded,
         * otherwise the call to FireOnChange in the SetDefaultView
         * method will fail. */
        if (viewCombo.readyState == "complete") {
    
          /* If the control already has finished loading, we can
           * directly set the new view. */
          SetDefaultView(viewCombo, "All", appGrid);
        }
    
        else {
          /* Otherwise we have to register another event handler
          * waiting until all of the include files used by the
          * combo box are loaded as well. */
          viewCombo.onreadystatechange = function() {
            if (this.readyState == "complete") {
              SetDefaultView(this, "All", appGrid);
            }
          }
        }
      }
    }
    
    
    /* Set a new onclick event for the History navigation element
     * This is where we register the onreadystatechange event handler */
    if (document.getElementById('navActivities') != null) {
      document.getElementById('navActivities').onclick = function() {
        loadArea('areaActivities');
        document.frames('areaActivitiesFrame').document.onreadystatechange = areaActivitiesFrame_OnReadyStateChange;
      }
    }
    
    
    /**************************************************************
    * End - Change the default view of a view selection combo box
    **************************************************************/
    
    

    MayankP
    My Blog
    Follow Me on Twitter
    • Proposed As Answer by Faisal Fiaz Tuesday, January 18, 2011 11:54 AM
    • Marked As Answer by CasperDK Wednesday, January 19, 2011 12:34 PM
    •  
  • Tuesday, January 18, 2011 1:12 PM
     
     

    Hi MayankP

     

    we meet again :)

     

    I will look into it...

     

    ITs not me per say whos going to implement the code so please bear with me if im taking a little longer then usuall to respond if the post is answered or not :)

     

    /Casper 

  • Wednesday, January 19, 2011 12:34 PM
     
     
    This will take some time to test apparently so i will go ahead and mark your post as answered.. :) thanks for the help
  • Tuesday, November 29, 2011 6:02 AM
     
     

    Thank you for this very useful code MayankP.   I am using the code you provided above with a very slight modification successfully in CRM 2011. 

    Here is the code for anyone else who needs in for 2011:

    //Type = entity type, e.g. Contact or Account
    //For example, to default a contact form, pass "Contact" as the parameter from your onload event


    function SetView(Type)
    {
    SetDefaultView = function(viewCombo, viewName, appGrid) {

      if (viewCombo.value != viewName) {

        viewCombo.value = viewName;

        appGrid.RefreshGridView();
      }
    }


    areaActivitiesFrame_OnReadyStateChange = function() {

      if (this.readyState == "complete") {

        var frame = document.frames("areaActivitiesFrame");
        var viewType = "crmGrid_"+Type+"_ActivityPointers_datefilter"
        var viewCombo = frame.document.getElementById(viewType);

        var appGrid = frame.document.getElementById("AppGridFilterContainer");

        if (viewCombo.readyState == "complete") {

          SetDefaultView(viewCombo, "All", appGrid);
        }

        else {

          viewCombo.onreadystatechange = function() {
            if (this.readyState == "complete") {
              SetDefaultView(this, "All", appGrid);
            }
          }
        }
      }
    }

    if (document.getElementById('navActivities') != null) {
      document.getElementById('navActivities').onclick = function() {
        loadArea('areaActivities');
        document.frames('areaActivitiesFrame').document.onreadystatechange = areaActivitiesFrame_OnReadyStateChange;
      }
    }
    }


    JBM

    • Edited by MMBI Thursday, December 01, 2011 12:45 PM
    •  
  • Thursday, March 08, 2012 8:54 PM
     
     

    Hi Mayank,

    I am totally in Casper's above mention situation.

    Is this a clean solution for this. Also, is that script can work with CRM 2011.

    I saw couple of post that used JScript to accomplish the requirement.

    Also the customization that you are suggesting, support the outlook client and mobile client.

    If you can share your approach that would be Great.

    Thanks.


    Puneet Joshi