locked
Hiding grid buttons in MSCRM RRS feed

  • Question

  • Hi,

    I am having different view in the Quote Grid. On a particular view selection(Let say Eg:My Quotes) i want to show a button and on the other cases i want to Hide it. How this can be achieved?

    Thanks
    sini_tg
    Friday, February 26, 2010 11:39 AM

Answers

  • Here's how you add javascript to a CRM views

    http://mscrm4ever.blogspot.com/2008/09/decorating-crmgrid-columns.html


    This How-To Post is about decorating grid columns. Once you understand the mechanics behind the code the rest is a simple (or not) manifest of your / customer’s imagination. You should consider the ramifications of using this type of functionality since this might not upgrade to the next version.

    The general idea is to override a sitemap link, contacts SubArea link in the workplace Area customers Group in this case, with a new url which contains an IFRAME to the original / Desired CrmGrid.

    The JavaScript code in the new aspx page has 2 functionalities:
    1. Handles the IFRAME and CrmGird loads and between Refreshes.
    2. Contains the code you provide to Decorate the column cells.
    [SJ: In your case add onchange event to the CRM views drop down]


    @_Simon_Jackson http://www.simonjackson.info/ MBCS MCBMSS MCBMSP MCSD MCDBA MCAD MCSA
    Sunday, February 28, 2010 9:50 PM
  • I don't think there's any simple way to do this. The techniques described in http://mscrmuk.blogspot.com/2007/12/providing-different-default-views-for.html could be used to get client script to run at the right time to do what you want.


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Thursday, March 18, 2010 8:58 PM
    Moderator
  • sini follow _Simon_Jackson referred link http://mscrm4ever.blogspot.com/2008/09/decorating-crmgrid-columns.html

    you html page code will look like this

    <%@ Page Language="C#" %>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Quote</title>
        <script language="javascript">

     

      attachEvent( "onload" , OnPageLoad );
      //IFrame ID
      var contsGrid;
      //IFrame document object
      var iframeDoc;
      //Views picklist 
      var SavedQuerySelector;
      //The grid object
             var crmGrid;
       
      /*
       Load the contacts grid view,
       You may change the IFRAME url to suit your needs
      */
      function OnPageLoad()
      {
       contsGrid = document.all.contsGrid;
       var contsUrl  = "/" + top.ORG_UNIQUE_NAME + "/_root/homepage.aspx?etc=2"; 
       contsGrid.src = contsUrl;
       contsGrid.onreadystatechange = OnGridViewReady;
      }
      
      /*
       When the IFRAME is ready then:
       Attach to the grid refresh and selector change events.
       Since the grid is already loaded call it for the first time.
      */
      function OnGridViewReady()
      {
       if( contsGrid.readyState != "complete" ) 
        return;
       iframeDoc = contsGrid.contentWindow.document;
       
       //make sure the selector exists
       SavedQuerySelector = iframeDoc.all.SavedQuerySelector;
       if( SavedQuerySelector )
        iframeDoc.all.SavedQuerySelector.attachEvent( "onchange" , OnGridReadyChangeLayout );
       
       //make sure the grid exists
       crmGrid = iframeDoc.all.crmGrid;
       if( crmGrid )
       {
        iframeDoc.all.crmGrid.attachEvent( "onrefresh" , OnGridReadyChangeLayout );
        //change the layout for the first time
        OnGridReadyChangeLayout();
       }  
      }
      
      /*
       This function (callback) is called every time the 
       grid view refreshes either by the selector or refresh button.
       
       IF the Data( InnerGrid ) is not ready then the setTimeout is called.      
      */
      function OnGridReadyChangeLayout()
      {
       if( !crmGrid.InnerGrid ) 
        return setTimeout( OnGridReadyChangeLayout , 100 );
       
             /* Put your implementations under this line */
       
    /* Get Views Dropdown list check its selected view and hide your required button*/
    
      if(SavedQuerySelector[SavedQuerySelector.selectedIndex].text == "<<your required view name>>" && SavedQuerySelector[SavedQuerySelector.selectedIndex].selected == true)
            {
                   iframeDoc.all.<<your required button>>.style.display="none";
            }
      }
      
     
    

     

     

     </script>
    </head>
    <body scroll="no" style="margin:0px">
        <iframe id="contsGrid" 
       src="about:blank" 
       style="width:100%;height:100%" 
       frameborder="0" 
       scrolling="no">
     </iframe>
    </body>
    </html>
    

     

     

     

     


    http://www.allaboutdynamics.com
    Friday, March 19, 2010 7:58 AM

All replies

  • Hi,

    I am having different view in the Quote Grid. On a particular view selection(Let say Eg:My Quotes) i want to show a button and on the other cases i want to Hide it. How this can be achieved?

    Thanks
    Sini
    sini_tg
    Friday, February 26, 2010 6:03 AM
  • Hi,

    I'm not exactly sure about what button you want to show or hide but all those configurations are achieved by using the ISV.config file.

    Check the SDK or more specifically this pages:
    http://technet.microsoft.com/en-us/library/bb928136.aspx
    http://technet.microsoft.com/en-us/library/cc150896.aspx
    http://technet.microsoft.com/en-us/library/cc150842.aspx

    HTH,
    Andre
    Friday, February 26, 2010 12:36 PM
  • Hi Sini:

    As noted by Andre the SDK ahs informaiton on adding buttons to forms, but it from your question it sounds like you need to show/hide buttons based on some dynamic criteria...If that's what you're looking for you need to use JavaScript...

    If you provide more details I might be able to provide a concrete example.

    John.
    Friday, February 26, 2010 2:08 PM
    Moderator
  • Hi,

    Its not in the form where i have to hide. I have the grid view of records for an entity. that had got different views like "My Quote"/"All Quote" etc. I will be selecting views from there to see the data related to that.

    On the same time i have put a custom button on the grid view menu bar, Depending on the selection of the view i need to hide/view that custom button.

    Sini


    sini_tg
    Friday, February 26, 2010 3:04 PM
  • As per the links given its showing how to add buttons in menubar of grid. i am looking how to hide it on selection of a particualr view.

    sini_tg
    Friday, February 26, 2010 5:03 PM
  • Sini_tg what you are looking is not so simple, because there is no existing interface for adding javascript to CRM views, which capture CRM view controls actions and perform any custom behavior.

    There is only one way (about which i am not sure, just testing) that by some mean we can able to attach an "onChange" event to CRM views drop-down control. Then that event can do show/hide or etc.

    From Opportunity form we can easily attach event to to Quote View by getting Quote View Iframe, on Iframe.ready "state-complete" get Views drop-down and attach event "OnChange" written in Oppoertunity Form. 

    But it only works inside Opportunity Form, we need to find some way else for Main CRM form.

    http://www.allaboutdynamics.com
    Friday, February 26, 2010 5:48 PM
  • Here's how you add javascript to a CRM views

    http://mscrm4ever.blogspot.com/2008/09/decorating-crmgrid-columns.html


    This How-To Post is about decorating grid columns. Once you understand the mechanics behind the code the rest is a simple (or not) manifest of your / customer’s imagination. You should consider the ramifications of using this type of functionality since this might not upgrade to the next version.

    The general idea is to override a sitemap link, contacts SubArea link in the workplace Area customers Group in this case, with a new url which contains an IFRAME to the original / Desired CrmGrid.

    The JavaScript code in the new aspx page has 2 functionalities:
    1. Handles the IFRAME and CrmGird loads and between Refreshes.
    2. Contains the code you provide to Decorate the column cells.
    [SJ: In your case add onchange event to the CRM views drop down]


    @_Simon_Jackson http://www.simonjackson.info/ MBCS MCBMSS MCBMSP MCSD MCDBA MCAD MCSA
    Sunday, February 28, 2010 9:50 PM
  • I don't think there's any simple way to do this. The techniques described in http://mscrmuk.blogspot.com/2007/12/providing-different-default-views-for.html could be used to get client script to run at the right time to do what you want.


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Thursday, March 18, 2010 8:58 PM
    Moderator
  • sini follow _Simon_Jackson referred link http://mscrm4ever.blogspot.com/2008/09/decorating-crmgrid-columns.html

    you html page code will look like this

    <%@ Page Language="C#" %>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Quote</title>
        <script language="javascript">

     

      attachEvent( "onload" , OnPageLoad );
      //IFrame ID
      var contsGrid;
      //IFrame document object
      var iframeDoc;
      //Views picklist 
      var SavedQuerySelector;
      //The grid object
             var crmGrid;
       
      /*
       Load the contacts grid view,
       You may change the IFRAME url to suit your needs
      */
      function OnPageLoad()
      {
       contsGrid = document.all.contsGrid;
       var contsUrl  = "/" + top.ORG_UNIQUE_NAME + "/_root/homepage.aspx?etc=2"; 
       contsGrid.src = contsUrl;
       contsGrid.onreadystatechange = OnGridViewReady;
      }
      
      /*
       When the IFRAME is ready then:
       Attach to the grid refresh and selector change events.
       Since the grid is already loaded call it for the first time.
      */
      function OnGridViewReady()
      {
       if( contsGrid.readyState != "complete" ) 
        return;
       iframeDoc = contsGrid.contentWindow.document;
       
       //make sure the selector exists
       SavedQuerySelector = iframeDoc.all.SavedQuerySelector;
       if( SavedQuerySelector )
        iframeDoc.all.SavedQuerySelector.attachEvent( "onchange" , OnGridReadyChangeLayout );
       
       //make sure the grid exists
       crmGrid = iframeDoc.all.crmGrid;
       if( crmGrid )
       {
        iframeDoc.all.crmGrid.attachEvent( "onrefresh" , OnGridReadyChangeLayout );
        //change the layout for the first time
        OnGridReadyChangeLayout();
       }  
      }
      
      /*
       This function (callback) is called every time the 
       grid view refreshes either by the selector or refresh button.
       
       IF the Data( InnerGrid ) is not ready then the setTimeout is called.      
      */
      function OnGridReadyChangeLayout()
      {
       if( !crmGrid.InnerGrid ) 
        return setTimeout( OnGridReadyChangeLayout , 100 );
       
             /* Put your implementations under this line */
       
    /* Get Views Dropdown list check its selected view and hide your required button*/
    
      if(SavedQuerySelector[SavedQuerySelector.selectedIndex].text == "<<your required view name>>" && SavedQuerySelector[SavedQuerySelector.selectedIndex].selected == true)
            {
                   iframeDoc.all.<<your required button>>.style.display="none";
            }
      }
      
     
    

     

     

     </script>
    </head>
    <body scroll="no" style="margin:0px">
        <iframe id="contsGrid" 
       src="about:blank" 
       style="width:100%;height:100%" 
       frameborder="0" 
       scrolling="no">
     </iframe>
    </body>
    </html>
    

     

     

     

     


    http://www.allaboutdynamics.com
    Friday, March 19, 2010 7:58 AM