Tuesday, July 28, 2020

Custom Icons for DateTime fields in D365 Views

Hi again,
as you might know, there is a supported possiblity how to display custom icons in D365 Customer engagement views.
It's described here:

I will not go through the same steps, I just wanted to share a more info on top of this.

I needed to get the icons to the case views where we have SLA deadline. When deadline is in far future, we want green icon, when it is approaching, we want orange and when the deadline is breached, we want the icon red.

So what yyou need to do is follow the above guide, create icons, create webresource and in that web rource use script like this:
 

function displayIcon(rowData) {     

    var str = JSON.parse(rowData);

    //new datetime variable

    var checktime = new Date();

    //add 2 hours - needed to evaluate orange icon

    checktime.setHours(checktime.getHours()+2);

    //current time

    var today = new Date();

   

    //read datetime value - it is returned as a string!

    var slastage = str.new_slastageend;

   // convert to datetime object

    var slastageend = new Date(slastage);

   

    var imgName = ""; 

    var tooltip = "";

 

    compare object

    if (checktime.getTime() > slastageend.getTime() && today.getTime() < slastageend.getTime())

        {

             imgName = "orange.png"; 

             tooltip = "SLA Near Breach"; 

        }

    else if (checktime.getTime() < slastageend.getTime())

         {

             imgName = "green.png"; 

             tooltip = "SLA OK";         

         }   

       

    else if (checktime.getTime() > slastageend.getTime())

        {

             imgName = "red.png"; 

             tooltip = "SLA Breached"; 

        }

 

    var resultarray = [imgName, tooltip]; 

    return resultarray; 



So really, the trick here is to convert the string to datetime and then it is very easy. Also based on this finding, you can see that it is possible to add the icon to any column of any type.

Michal