Friday, September 23, 2011

How to add color to a Microsoft CRM 2011 Form Picklist

Add color to target picklist is a very simple task. I will show you an example on Task form, Priority Picklist.
It has three options: Low, Normal, High.
Let’s add colors for them: Yellow, Green and Red.

Simply add OnLoad event:

function AddColorToPriority()
{
crmForm.all["prioritycode"][0].style.background = "#FFF380"; // Low => Yellow
crmForm.all["prioritycode"][1].style.background = "#5EFB6E"; // Normal => Green
crmForm.all["prioritycode"][2].style.background = "#E55451"; // High => Red
}


Here is other way to implement it:

function AddColorToPrioritySecond()
{
crmForm.all.prioritycode[0].style.background = "yellow"; // Low => Yellow
crmForm.all.prioritycode[1].style.background = "green"; // Normal => Green
crmForm.all.prioritycode[2].style.background = "red"; // High => Red
}

1 comment:

  1. This is great, thank you. Is there a way to change the text color (CRM 2011) rather than the background?

    Here is the snippet I am using:
    var list = Xrm.Page.getAttribute(field).getOptions();

    for(var i = 0; i < list.length; ++i){
    if (list[i].value == 100000000 || list[i].value == 100000002) {
    list[i].style.color='#FF0000'; // Bright Red
    }

    When I run this I get an error that it can't set the color attribute.

    ReplyDelete