Highlight overdue dates

This question is not answered

Hi, 

I have found this script that highlights dates on a list view if they are Today or Tommorow. How can I adapt this script so that it highlights dates that are less than today (overdue).

<script>

$(document).ready(function()

{
var obj =

{
color: “#4d4f53”,
};

crm.grids().rows().cells().highlightCell(obj);
crm.ready(function ()

{
crm.grids().rows().column(‘lead_rateddate’).exec
(function (index, currentCell)
{

var cellHtml = $(currentCell).html();
if (cellHtml.includes(“Today”) || cellHtml.includes(“Tomorrow”))

{
$(currentCell).css(‘background-color’, ‘greenyellow’);
}

});

});

});
</script>

All Replies
  • Like this:

    <script>

    crm.ready(function() {

     var today = new Date();

     crm

       .grids()

       .rows()

       .column("lead_rateeddate")

       .exec(function(index, currentCell) {

         var cText = currentCell.innerText.match(

           /^([0-2][0-9]|(3)[0-1])(\/)(((0)[0-9])|((1)[0-2]))(\/)\d{4}/

         )[0];

         var dParts = cText.split("/");

         var celldate = new Date(dParts[2], dParts[1] - 1, dParts[0]);

         if (celldate.getDate() < today.getDate()) {

           $(currentCell).css("background-color", "greenyellow");

         }

       });

    });

    </script>

    You could make the date parsing and comparing a lot easier with something like moment.js, but the stuff above will do.