locked
Select custom view as associated view RRS feed

  • Question

  • Hi,

    We have several account types and want to display different associated views per account type.

    For example when you are on an opportunity record and click on suppliers in the left nav, it should display the supplier specific associated view by default (I know that the user can select a different view manually but the business requires it to be defaulted).

    If I then click on a customer account link I want to see the associated view that contains the customer specific columns.

    Customers and suppliers are both stored in the system as an account (also a business requirement)

    Is there a way to display a different custom view per account type dynamically?

    Thanks!

    Wednesday, April 20, 2011 2:36 PM

Answers

  • Yes. It is possible.

    First options is based on account type you can change the default filter in account view. Check these:-

    http://www.stunnware.com/crm2/topic.aspx?id=js33

    http://mscrm4ever.blogspot.com/2008/07/changing-activity-history-default-view.html

    http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/85615ccd-b8e9-48d3-a906-4fd7b301dac0

    The above will do the filtering in views and you can add the logic that it should work on Account Type.

    Now if you want to have different columns also that you will have to think of creating custom html iframes. An example is as under:-

    <html>
    <head>
    
      <script type="text/javascript">
         var AccountID = parent.document.forms[0].all.objectid;
        // alert(AccountID);
    
        function getFetchXML() {
          var strXML = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="annotation"><attribute name="createdby"/><order attribute="createdon" descending="false"/><link-entity name="account" from="accountid" to="objectid" alias="aa"><filter type="and"><condition attribute="accountid" operator="eq" uitype="account" value="' + AccountID + '"/></filter></link-entity></entity></fetch>';
          //alert(strXML);  
          return strXML;
        }
      </script>
    
      <meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
    </head>
    <body onload="document.getElementById('fetchinput').value = getFetchXML();resultRender.submit();">
      <form id="resultRender" action="http://ServerName/OrganisationName/AdvancedFind/fetchData.aspx" method="post">
      <input type="hidden" name="FetchXml" id="fetchinput" value='' /><input type="hidden"
        name="LayoutXml" value='<grid name="resultset" object="5" jump="" select="1" icon="1" preview="1"><row name="result" id="annotationid"><cell name="subject" width="130" /><cell name="notetext" width="160" /></row></grid>' />
      <input type="hidden" name="EntityName" value="annotation" />
      <input type="hidden" name="DefaultAdvFindViewId" value="{DDDFF6AE-2F52-4640-B2BB-2BA59DA0777C}" />
      <input type="hidden" name="ViewId" value="{DDDFF6AE-2F52-4640-B2BB-2BA59DA0777C}" />
      <input type="hidden" name="ViewType" value="1039" />
      <input type="hidden" name="SortCol" value="subject" />
      <input type="hidden" name="SortDescend" value="false" />
      </form>
    </body>
    </html>
    

     


    Regards Faisal
    Wednesday, April 20, 2011 3:48 PM
  • 0

    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 4:08 PM

All replies

  • Yes. It is possible.

    First options is based on account type you can change the default filter in account view. Check these:-

    http://www.stunnware.com/crm2/topic.aspx?id=js33

    http://mscrm4ever.blogspot.com/2008/07/changing-activity-history-default-view.html

    http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/85615ccd-b8e9-48d3-a906-4fd7b301dac0

    The above will do the filtering in views and you can add the logic that it should work on Account Type.

    Now if you want to have different columns also that you will have to think of creating custom html iframes. An example is as under:-

    <html>
    <head>
    
      <script type="text/javascript">
         var AccountID = parent.document.forms[0].all.objectid;
        // alert(AccountID);
    
        function getFetchXML() {
          var strXML = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="annotation"><attribute name="createdby"/><order attribute="createdon" descending="false"/><link-entity name="account" from="accountid" to="objectid" alias="aa"><filter type="and"><condition attribute="accountid" operator="eq" uitype="account" value="' + AccountID + '"/></filter></link-entity></entity></fetch>';
          //alert(strXML);  
          return strXML;
        }
      </script>
    
      <meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
    </head>
    <body onload="document.getElementById('fetchinput').value = getFetchXML();resultRender.submit();">
      <form id="resultRender" action="http://ServerName/OrganisationName/AdvancedFind/fetchData.aspx" method="post">
      <input type="hidden" name="FetchXml" id="fetchinput" value='' /><input type="hidden"
        name="LayoutXml" value='<grid name="resultset" object="5" jump="" select="1" icon="1" preview="1"><row name="result" id="annotationid"><cell name="subject" width="130" /><cell name="notetext" width="160" /></row></grid>' />
      <input type="hidden" name="EntityName" value="annotation" />
      <input type="hidden" name="DefaultAdvFindViewId" value="{DDDFF6AE-2F52-4640-B2BB-2BA59DA0777C}" />
      <input type="hidden" name="ViewId" value="{DDDFF6AE-2F52-4640-B2BB-2BA59DA0777C}" />
      <input type="hidden" name="ViewType" value="1039" />
      <input type="hidden" name="SortCol" value="subject" />
      <input type="hidden" name="SortDescend" value="false" />
      </form>
    </body>
    </html>
    

     


    Regards Faisal
    Wednesday, April 20, 2011 3:48 PM
  • 0

    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 4:08 PM