locked
CRM 2011: color-coding records in the grid RRS feed

  • Question

  • 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

    Friday, April 20, 2012 1:35 PM

Answers

  • 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

    • Marked as answer by lana7220 Thursday, April 26, 2012 3:29 PM
    Thursday, April 26, 2012 2:21 PM

All replies

  • 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

    Friday, April 20, 2012 2:43 PM
  • 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


    • Edited by lana7220 Friday, April 20, 2012 3:29 PM
    Friday, April 20, 2012 2:52 PM
  • 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

    Saturday, April 21, 2012 10:44 PM
    Answerer
  • Does this article apply to CRM 2011? Thanks

    Lana Feldman

    Tuesday, April 24, 2012 3:43 PM
  • 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

    Tuesday, April 24, 2012 8:10 PM
  • Hi Lana

    Would like to see how this is done. 

    Wednesday, April 25, 2012 8:14 AM
  • 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

    • Marked as answer by lana7220 Thursday, April 26, 2012 3:29 PM
    Thursday, April 26, 2012 2:21 PM
  • 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.

    Thursday, April 26, 2012 5:22 PM
  • Hi. I've set up conditional formatting in the Outlook.

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

    Thanks. 


    Lana Feldman

    Friday, May 4, 2012 7:36 PM
  • 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!

    Wednesday, May 9, 2012 4:05 PM
  • 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!

    Thursday, May 17, 2012 8:40 PM
  • 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

    Thursday, May 17, 2012 9:00 PM
  • 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.
    Thursday, May 17, 2012 9:13 PM
  • 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.

    Thursday, September 13, 2012 5:20 AM
  • What IE version do you use? This misbehavior doesn't happened for us.

    Lana Feldman

    Thursday, September 13, 2012 1:29 PM
  • Hi lana,

    Thanks for your reply.

    I am using IE8.

    Thursday, September 13, 2012 1:58 PM
  • We have IE8 also. Double check the code. It should work.

    Lana Feldman

    Thursday, September 13, 2012 3:13 PM
  • 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",

    Friday, September 14, 2012 4:49 AM
  • 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

    Friday, September 14, 2012 1:38 PM
  • Hi lana,

    I have that file ay my mentioned location.

    Dont know what is the reason..

    Monday, September 17, 2012 4:36 AM
  • 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"; } } } }


    • Proposed as answer by DynamicsCRM31 Tuesday, September 18, 2012 12:04 PM
    Tuesday, September 18, 2012 7:12 AM
  • Hi Milan..let me know if this works with CRM 2011 as well...
    Thursday, August 1, 2013 4:24 AM
  • Hi Lana,

    i tried with your code..but its not working..i m using crm 2011..

    let me know if it works in 2011 version also..

    Thursday, August 1, 2013 4:26 AM