CRM 2011: color-coding records in the grid

Answered CRM 2011: color-coding records in the grid

  • 20 April 2012 13:35
     
     

    Hello all.

    Please do not get upset that I am doing something unsupported. Without this feature we can't upgrade from 4.0 to 2011!

    We need to color-code a custom column "Rating" on Leads view that works in IE .  If record has attribute  "hot",  then this record must have red background in this column.

    We had this working in 4.0, but now I need to fix the code to work in 2011. 

    I've added simple function in  MS Dynamics CRM/CRMWeb/_root/HomePage.aspx:

    <body onload="alterGridRecords()" >

    function alterGridRecords(){   ....

    var grid = document.getElementById("gridBodyTable").lastChild;

    var gridTH = document.getElementById("gridBodyTable")

    var headers = gridTH.getElementsByTagName("TH");

    for (var n = 0; n < headers.length; n++)

       {   var header = headers[n];     

           if (header.innerText == "Color Code"){

               for (var i = 0; i < grid.childNodes.length; i++)  {

                   if (grid.childNodes[i].childNodes[n].innerText=='Hot')

                        {grid.childNodes[i].childNodes[n].style.backgroundColor="ff6666";} ....

    It works perfectly but only when I load Leads for the first time. If I switch to another view and then go back to this one, there is no color in my column.  I think the code is in the wrong place. I'd like it to work on all the Lead's grids .

    Please help.


    Lana Feldman

Semua Balasan

  • 20 April 2012 14:43
     
     

    Hi Lana

    I assume that you are placing it on the onload event?  If you look at what is happening in the background, the form only change the colors once it is loaded on that view.  I have also tried to change the colors without any hope.

    The best solution I could find was to add colors to Outlook and use Outlook instead to view the grid. 


    Please vote if you find my post useful. Add me on @ Skype christo.skype1

  • 20 April 2012 14:52
     
     

    Good to know that I am not alone!

    In Version 4.0 similar code I placed in _static/_grid/ grid.htc  in function initializeData(). It worked like a charm.

    What do you think is an equvalent in 2011?


    Lana Feldman


    • Diedit oleh lana7220 20 April 2012 15:29
    •  
  • 21 April 2012 22:44
    Penjawab Pertanyaan
     
     

    Hi Lana,

    I think this may help you:

    http://blog.odynia.org/?p=18

    Regards

    Nuno


    Visit my blog for CRM material, improving performance, kerberos, IFD, development tips, etc. :) http://quantusdynamics.blogspot.com

  • 24 April 2012 15:43
     
     
    Does this article apply to CRM 2011? Thanks

    Lana Feldman

  • 24 April 2012 20:10
     
     

    I got it! This is the article that helped me:

    weblogs.asp.net/.../how-to-change-the-grid-icons-dynamically.aspx

    If anyone needs my solution, happy to share. Works beautifully. I hope next CRM version will support this feature.


    Lana Feldman

  • 25 April 2012 8:14
     
     

    Hi Lana

    Would like to see how this is done. 

  • 26 April 2012 14:21
     
     Jawab Memiliki Kode

    In “MS Dynamics CRM/CRMWeb/_grid/AppGrid.css.aspx”:

    .ms-crm-List-Data

     behavior: url…  url(<%=CrmUri.Create("/ISV/colorizeGrid.htc", Microsoft.Crm.Application.Security.UserInformation.Current).ToString()%>);

    Create file in ISV folder colorizeGrid.htc:

    <public:component lightweight="true"> <public:attach event="ondocumentready" onevent="alterGridRecords()"/> <script type="text/javascript"> function alterGridRecords(){ if (this.oname != "4") {return;} //I only do it for Leads (id 4) for (var j = 0; j < this.rows[0].cells.length; j++) { if (this.rows[0].cells[j].innerText == "Color Code") { var colorizeColumn =j; } } if (colorizeColumn > 0) { for (var i = 0; i < this.rows.length; i++) { if (this.rows[i].cells[colorizeColumn].innerText=="Hot") {his.rows[i].cells[colorizeColumn].style.backgroundColor="ff6666";}

    //and so on for all "Colors" .................

    </script></public:component>




    Lana Feldman

    • Ditandai sebagai Jawaban oleh lana7220 26 April 2012 15:29
    •  
  • 26 April 2012 17:22
     
     

    First, I admit to using this approach on occasion when needed. Secondly, I would also say I am not counting on this exact method to continue to work, especially when cross-browser CRM is released, so just be sure to set the appropriate expectations for 'unsupported' customizations.

  • 04 Mei 2012 19:36
     
     

    Hi. I've set up conditional formatting in the Outlook.

    Could someone tell me how to share this view with others?

    Thanks. 


    Lana Feldman

  • 09 Mei 2012 16:05
     
     

    I assume this only works for CRM 2011 On-Premise, not CRM Online.

    Will use it when we finally move to on-premise. Thanks Lana!

  • 17 Mei 2012 20:40
     
      Memiliki Kode

    Lana, thanks so much, this is great. I implemented your solution, but just changed the alterGridRecords to do a Hello World alert.. once I get the function to fire I'll worry about the actual logic.

    <public:component lightweight="true"> <public:attach event="ondocumentready" onevent="alterGridRecords()"/> 
    <script type="text/javascript"> 
    function alterGridRecords()
    { 
    alert("Colorize");
    }
    
    </script></public:component>

    My issue at the moment is that the jScript doesn't appear to fire. I pulled the AppData.css.aspx file from the browser and got this:

    .ms-crm-List-Data
    {
    table-layout: fixed;
    width: 100%;
    behavior: url(/ISV/colorizeGrid.htc?ver=1411856737) url(/_static/_grid/appgrid_defaultdata.htc?ver=1411856737);
    }

    so the call to the custom htc file is there. But my jScript isn't firing. I think the reason for this is that the appgrid_defaultdata.htc file also contains an "ondocumentready" function.

    Is this why my jScript isn't firing? If so, how do I overcome this? Thanks in advance!

  • 17 Mei 2012 21:00
     
     

    I'd say first, delete temp files in the browser, then do crl+refresh, then open a new browser. I had to do this with every change of Javascript. There is something gets cached in IE... 

     Let me know. 


    Lana Feldman

  • 17 Mei 2012 21:13
     
     
    Thanks, Lana. I was clearing my history using the IE tools but I had to go into my Temp Internet Files directly and delete all its contents. That got the Hello, World to work.
  • 13 September 2012 5:20
     
     

    Hello lana,

    I have tried this solution, It works.

    But because of this ,grid misbehaves.. Select all does not work.. and all ribbon button becomes unclickable.. and most strange is that that record doesnt opend in form by double click and by clicking on field.

    What may be the solution ? Please suggest.

  • 13 September 2012 13:29
     
     
    What IE version do you use? This misbehavior doesn't happened for us.

    Lana Feldman

  • 13 September 2012 13:58
     
     

    Hi lana,

    Thanks for your reply.

    I am using IE8.

  • 13 September 2012 15:13
     
     
    We have IE8 also. Double check the code. It should work.

    Lana Feldman

  • 14 September 2012 4:49
     
     

    Hi lana,

    I have done this often.. But still this issue remains.

    let me conform.. In following url,

    url(<%=CrmUri.Create("/ISV/colorizeGrid.htc",

    I have written as follow.. Is because of this it doesnt work..??

    url(<%=CrmUri.Create("/_static/_grid/colorizeGrid.htc",

  • 14 September 2012 13:38
     
     

    The url must be the url pointing to the location of your colorizeGrid.htc file (or whatever you called the file containing the logic) If you put you colorizeGrid.htc file in /_static/_grid/ make sure that relatively this path is correctly specified. You could debug by putting the code in the same location I have and changing url to /ISV/colorizeGrid.htc

    See what happens.


    Lana Feldman

  • 17 September 2012 4:36
     
     

    Hi lana,

    I have that file ay my mentioned location.

    Dont know what is the reason..

  • 18 September 2012 7:12
     
     Saran Jawaban Memiliki Kode

    Hi lana,

    Nevermind.. I found another way that helped me to achieve the same.

    I have modified _root/HomePage.aspx page as below.. 

    <body class="stage" onload="alterGridRecords()">  --> I added onload="alterGridRecords().

    alterGridRecords() function is as below.

    function alterGridRecords() { //debugger; var sOtc = document.all['crmGrid'].GetParameter('otc'); var a = document.all["crmGrid"].InnerGrid.AllRecords; var rows = new Array(a.length); for (var i = 0; i < a.length; i++) { rows[i] = a[i][3]; } //sOtc = 3 means opportunity if (sOtc == 3) { for (var i = 0; i < rows.length; i++) { var nameCell = rows[i].cells[5]; if (nameCell.all[0].childNodes[0].nodeValue == "Red") { nameCell.childNodes[0].style.backgroundColor = "#FF0000"; } else if (nameCell.all[0].childNodes[0].nodeValue == "Green") { nameCell.childNodes[0].style.backgroundColor = "#00FF00"; } else { nameCell.childNodes[0].style.backgroundColor = "#FF6600"; } } } }


    • Disarankan sebagai Jawaban oleh Dynamics CRM 31 18 September 2012 12:04
    •