locked
Default filter on associated views RRS feed

  • Question

  • Hi all !

    I'd like to change the default filter for an associated view.

    By default, for the customer's contracts view, it is set on "draft", and i'd like to have it set on "active" by default.

    How can i do it ?

    Thanks in advance !

    EuG

    Tuesday, May 25, 2010 10:36 AM

Answers

  • Hi,

    You could use the following JavaScript in the onload of your account form.

     

    var navElement = document.getElementById('navContracts');
     if (navElement != null) {
      navElement.onclick = function LoadAreaOverride()  {  
       loadArea('areaContracts');
       SetDefaultOption(document.getElementById('areaContractsFrame'));
      }
     }
    
    
    
     
    function SetDefaultOption(Iframe) { 
     if (Iframe != null ) {
      Iframe.onreadystatechange = function SetOption() { 
       if (Iframe.readyState == 'complete') { 
        var iFrame = frames[window.event.srcElement.id]; 
        var selectBox=iFrame.document.getElementById('statecode');    
         selectBox.options[2].selected=true;         
       } 
      } 
     }
    }

     

     

     

     

    Regards,

    Nishant Rana

     


    http://nishantrana.wordpress.com
    • Marked as answer by EugeneMoulin Tuesday, May 25, 2010 12:53 PM
    Tuesday, May 25, 2010 11:19 AM
  • Hi all !

    I found the solution.

    Just add a selectBox.fireOnChange(); at the end of my code :

    function PositionnerFiltreVuesAssociees(Iframe, IndexFiltre)
    {
      if (Iframe != null)
      {
        Iframe.onreadystatechange = function SetOption()
        {
          if (Iframe.readyState == 'complete')
          {
            var iFrame = frames[window.event.srcElement.id];
            var selectBox = iFrame.document.getElementById('statecode');
            selectBox.options[IndexFiltre].selected = true;
            selectBox.FireOnChange();
          }
        }
      }
    }
    

    And it shall work at the first display...

    EuG

     

    • Marked as answer by EugeneMoulin Friday, August 27, 2010 3:36 PM
    Friday, August 27, 2010 3:35 PM

All replies

  • You should be able to achieve that by exporting the entity and editing the fetch xml for the associated view
    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Tuesday, May 25, 2010 11:15 AM
    Moderator
  • You should be able to achieve that by exporting the entity and editing the fetch Xml for the associated view
    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Tuesday, May 25, 2010 11:17 AM
    Moderator
  • Hi,

    You could use the following JavaScript in the onload of your account form.

     

    var navElement = document.getElementById('navContracts');
     if (navElement != null) {
      navElement.onclick = function LoadAreaOverride()  {  
       loadArea('areaContracts');
       SetDefaultOption(document.getElementById('areaContractsFrame'));
      }
     }
    
    
    
     
    function SetDefaultOption(Iframe) { 
     if (Iframe != null ) {
      Iframe.onreadystatechange = function SetOption() { 
       if (Iframe.readyState == 'complete') { 
        var iFrame = frames[window.event.srcElement.id]; 
        var selectBox=iFrame.document.getElementById('statecode');    
         selectBox.options[2].selected=true;         
       } 
      } 
     }
    }

     

     

     

     

    Regards,

    Nishant Rana

     


    http://nishantrana.wordpress.com
    • Marked as answer by EugeneMoulin Tuesday, May 25, 2010 12:53 PM
    Tuesday, May 25, 2010 11:19 AM
  • Thanks Nishant !

    It works fine and i can use it on any associated view.

    I've just made a change in the function :

    //Will set the filter selector to the FilterIndex value for the sepcified associated view
    function SetAssociatedViewDefaultFilter(Iframe, FilterIndex) { if (Iframe != null) { Iframe.onreadystatechange = function SetOption() { if (Iframe.readyState == 'complete') { var iFrame = frames[window.event.srcElement.id]; var selectBox = iFrame.document.getElementById('statecode'); selectBox.options[FilterIndex].selected = true; } } } }

    I've added the FilterIndex parameter to indicate wich filter is to be set.

    FilterIndex values can be found using the IE devlopper's tools. (pressing F12 on any crmForm)

    EuG

    Tuesday, May 25, 2010 12:27 PM
  • Hi,

    Thanks for making it more generic.

     

    Regards,

    Nishant Rana

     


    http://nishantrana.wordpress.com
    Tuesday, May 25, 2010 12:30 PM
  • Thanks Tanguy, but it doesn't work fot this querytype (2)

    Here is the XML from the customization export :

    <savedquery>
          <columnsetxml>
           <columnset version="3.0">
            <column>expireson</column>
            <column>new_typecontratid</column>
            <column>statecode</column>
            <column>activeon</column>
            <column>contractid</column>
            <ascend>new_typecontratid</ascend>
           </columnset>
          </columnsetxml>
          <iscustomizable name="Non">0</iscustomizable>
          <isquickfindquery name="Non">0</isquickfindquery>
          <isuserdefined name="Oui">1</isuserdefined>
          <isprivate>0</isprivate>
          <isdefault name="Oui">1</isdefault>
          <returnedtypecode formattedvalue="1 010">1010</returnedtypecode>
          <savedqueryid>{59EF9AB3-4784-4332-96CA-B4CA2D797929}</savedqueryid>
          <queryapi>AUTO</queryapi>
          <savedqueryidunique>{563BAC85-A269-4AB3-BBA2-5032857F29C6}</savedqueryidunique>
          <layoutxml>
           <grid name="contracts" object="1010" jump="title" select="1" icon="1" preview="1">
            <row name="contract" id="contractid">
             <cell name="new_typecontratid" width="300" />
             <cell name="statecode" width="140" />
             <cell name="activeon" width="100" />
             <cell name="expireson" width="100" />
            </row>
           </grid>
          </layoutxml>
          <customizationlevel formattedvalue="1">1</customizationlevel>
          <querytype formattedvalue="2">2</querytype>
          <LocalizedNames>
           <LocalizedName description="Vue associée Contrat" languagecode="1036" />
          </LocalizedNames>
          <Descriptions>
           <Description description="Informations de contrats dans le formulaire détaillé d'un compte ou contact associé." languagecode="1036" />
          </Descriptions>
         </savedquery>

    We can read "<querytype formattedvalue="2">2</querytype>" so we don't have any fetch query for this savedquery.

    If we had a type 4 query, we would have a fetch query.

    EuG

    Tuesday, May 25, 2010 12:53 PM
  • Nishant - thanks for this post - I've tried the javascript and it changed the default filter on from draft to active but no records appear on our accounts even if several active contracts are present.  Refreshing the view doesn't work but changing the filter on to all and back to active shows the records.  We use CRM 4.0

    As a follow up question we would like the filter to be set to "all" but I'm not a programmer - which line item in the javascript controls the option selected?

    Thanks for your help!

    Saturday, June 5, 2010 11:22 AM
  • Hi RS,

    This line makes the selection : selectBox.options[FilterIndex].selected = true;

    FilterIndex is the index number of the filter's line in the combobox.

    To have this script working the call to the function has to be done in the Load event of your form.

    EuG

     

     

    Monday, June 7, 2010 1:05 PM
  • Hi RS,

     

    I have exactly the same problem as you had. Selects the filter but then doesnt popluate the view properly according the filter.

    Did you find a fix to this?

     

    Thanks,

    B

    Friday, July 9, 2010 12:18 PM
  • Hi RS,

     

    I´m facing the same problem. We have a german CRM 4.0 with Update Rollup 11.

     

    Best regards

     

    Oliver

    Wednesday, July 28, 2010 1:50 PM
  • Hi all !

    I found the solution.

    Just add a selectBox.fireOnChange(); at the end of my code :

    function PositionnerFiltreVuesAssociees(Iframe, IndexFiltre)
    {
      if (Iframe != null)
      {
        Iframe.onreadystatechange = function SetOption()
        {
          if (Iframe.readyState == 'complete')
          {
            var iFrame = frames[window.event.srcElement.id];
            var selectBox = iFrame.document.getElementById('statecode');
            selectBox.options[IndexFiltre].selected = true;
            selectBox.FireOnChange();
          }
        }
      }
    }
    

    And it shall work at the first display...

    EuG

     

    • Marked as answer by EugeneMoulin Friday, August 27, 2010 3:36 PM
    Friday, August 27, 2010 3:35 PM
  • Works great!

     

    Thank you.

    Monday, August 30, 2010 3:31 PM
  • I would like to change the default view. Here is my code, but I have all the time the error and I do not see how to solve it:

    /************************************************* *************
    * Change the default view of a view selection combo box
    ************************************************** ************/
    SetDefaultView = function (viewCombo, viewName, appGrid) {

        
    / * If the view HAS Already Been Set, We Do not 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 exchange,
             
    * But not the content of the grid * /
            
    appGrid.RefreshGridView ();
        
    }
    }


    /************************************************* *************
    * Event handler. Called Whenever the ready state of the
    * AreaActivityHistoryFrame exchange.
    ************************************************** ************/
    areaActivityHistoryFrame_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 control AppGridFilterContainer 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
             
    * Will fail method. * /
            
    / / If (viewCombo.readyState == "complete") {

                
    / * If the control HAS Already finished loading, we can
                 
    * Directly set the new view. * /
                
    SetDefaultView (viewCombo, "All", appGrid);
            
    / /}

            
    / / Else {
                
    / * Otherwise We Have Another event handler to register
                
    * 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);
                    
    }
                
    }
            
    } * /
        
    }
    }


    onload = function () {
    / * 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 = areaActivityHistoryFrame_OnReadyStateChange;
    / / Document.frames ("areaActivitiesFrame"). Document.onreadystatechange SetDefaultOption = (document.getElementById ('areaActivities'));
    }
    }
    }

     

    When i added it on the onload event, i got always the error : Oject required!!!

    Monday, January 2, 2012 3:53 PM
  • Hi all !

    I found the solution.

    Just add a selectBox.fireOnChange(); at the end of my code :

    function PositionnerFiltreVuesAssociees(Iframe, IndexFiltre)
    {
      if (Iframe != null)
      {
        Iframe.onreadystatechange = function SetOption()
        {
          if (Iframe.readyState == 'complete')
          {
            var iFrame = frames[window.event.srcElement.id];
            var selectBox = iFrame.document.getElementById('statecode');
            selectBox.options[IndexFiltre].selected = true;
            selectBox.FireOnChange();
          }
        }
      }
    }
    

    And it shall work at the first display...

    EuG

     

    I use similar code I found here: 

    http://crmxpg.nl/wp/2010/06/01/change-default-filter-of-associated-view/comment-page-1/#comment-4589

    The problem is FireOnChange(). CRM 2011 does not like it and I got error: "Object doesn't support property or method 'FireOnChange"

    Is your code for Dynamics CRM 4 only?

    Thursday, March 29, 2012 9:50 PM