Upgraded JavaScript and OptionSet values

In CRM 4.0 the values returned from a Picklist were integers represented as strings. If you were referring to a Picklist value, you would refer to it like this:

 

if (crmForm.all.new_picklist.DataValue == "2")
{
    // do something 
}

In CRM 2011, the OptionSet value is returned as a true integer so the following code (converted into CRM 2011 object model) will not work:

 

if (Xrm.Page.getAttribute("new_picklist").getValue() == "2")
{
    // do something 
}

You need to modify it so the equality operator looks like this:

 

if (Xrm.Page.getAttribute("new_picklist").getValue() == 2)
{
    // do something 
}

This is something very important to remember and something that has cost me me quite a bit of debugging time.

Leave a Reply 0 comments