Dynamics CRM – Dynamically change row color in grid view






Sometimes we get requirements for visually appealing representation of data in CRM Grids.
Like, we have to cater to requirements like “High” Priority cases should appear in “Red” color, or like high gross revenue opportunities should appear highlighted in the Grid.

In this article, we will show grid rows of Qualified Leads in Green Color, Lost or Disqualified Leads in Red color and Newly created Leads in Yellow Color

Step 1: Create a web resource of JavaScript Type and paste the below code under Text Editor.

    function showLeadStatus(rowData, userLCID) {

    if (rowData == null || rowData == \’undefined\’return;

    // read rowdata
    var str = JSON.parse(rowData);

    // get leads status
    var coldata = str.statuscode_Value;

    //get row/record guid
    var rowId = str.RowId;

    if (coldata == null || coldata == \’undefined\’ || coldata.length < 1) return;

    switch (coldata) {

        case 4: //if \’Lost

   
            // This is the way to get the whole row
           // This syntax might get changed in your case based upon requirement
           // First you need to find the \’td\’ tag (by doing F12 in gridview) based on the attribute you want to color the grid view
           // For Example, here I am using lead status field (statusreason) and the \’td\’ of 
status reason  field is span that is why I have used span to get the \’td\’ then used the \’closest\’ method to get the \’tr\’ of that \’td\’ in order to make the row colorful


            $(\’span:contains(\”Lost\”)\’).closest(\’tr\’).css(\’background-color\’, \’coral\’)
            $(\’span:contains(\”Lost\”)\’).closest(\’tr\’).css(\’color\’, \’white\’)
 
            break;

        case 3: //if \’qualified\’:

            $(\’span:contains(\”Qualified\”)\’).closest(\’tr\’).css(\’background-color\’, \’greenyellow\’)
            $(\’span:contains(\”Qualified\”)\’).closest(\’tr\’).css(\’color\’, \’white\’)

            break;

        case 1: //if \’new\’:

            $(\’span:contains(\”New\”)\’).closest(\’tr\’).css(\’background-color\’, \’yellow\’)
           
            break;

        default:
          
            break;
    }

}

Step 2: Open \’All Leads\’ view and mention the web resource and function name. I have selected Status Reason field because we have to perform the logic based on Lead Status value.



Step 3: Save and Close the View. Publish the Entity to see the changes.

Cheers ✌

Advertisement

Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

11 thoughts on “Dynamics CRM – Dynamically change row color in grid view

  1. Hello, do you know if th same issue is possible in Unified Interface ?Currently a line like \”$('span:contains(\”New\”)')\” doesn't work in new interface.TanksJerome

    Like

  2. Hi Arpit,Could you help me? I tried to apply everything in from above but nothing happens when I tried to open the view. Is there limitations on this? did I missed any triggers that not mentioned on this blog? Please help.

    Like

  3. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time. Contact him now and thank me later.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: