Just thought I’d share a bug I ran into with everyone and hope it helps you avoid it.
I see plenty of code that sets picklist values. You might do this in javascript, or in the CRM API. Set a new value, submit the update, picklist value is changed.
But, it’s easy to miss that picklist has two fields: a Name, and a Value. Value is something boring like 2, name is something to show to the user, like “Critical”.
You would think that writing code like this was great:
Picklist prop = source.Properties[attribute] as Picklist;
if (prop == null || prop.IsNull)
{
return defaultvalue;
}
return prop.name;
However, a problem crops up when dealing with client code written by people who didn’t understand that the name field is important. If you put that code into a plugin, you get passed straight the name + value that the API client specified – so you could run into javascript code that only changed the value, or into other CRM API code that only changed the value, and name can either be completely not set, or worse, set to an old previous value.
So, when writing server side code that handles data submitted by the client, it looks like you’ll need to only trust the value and ignore the name. It’s possible you could audit your client code and make sure that everywhere a new value is set a new name is set too.. but one day somebody will find some code from another project, add it to yours, and your picklist handling will be wrong.
Happy Thanksgiving!