Inside Microsoft CRM


Setting default values

So, I was just thinking about the picklist / boolean problem with default values. Let's just say I ran across something that looked suspicious to me in the newsgroup. For example, let's say I've added a pair of custom picklist values, one to opportunity and one to lead and let's say that I've set default values for those picklists. Now, one might suspect that running a "convert lead to opportunity" process would automatically set the default value on the picklist. If you launch the lead in the UI, sure enough, you find the picklist with the correct value *displayed*. That's the catch. The application is being really smart here and has noticed that the platform didn't give it a value in the document, so it painted the picklist the best way it could - with a value.

So, how can we get around this problem. There's the supported way of creating a mapping between the attributes on opportunity and lead. That works if you're trying to carry that data forward to the opportunity. The unsupported way is to tell the metadata what the default value should be, regenerate the views and triggers for that entity, and then start saving or updating things.

So, how does one do that you might ask. Well, if you know the value of the picklist item that you want to set as the default, update the Attribute table's DefaultValue column with that value. The only thing is that you need to get the metadata format correct. For numbers, the format is "(number)" and for strings the value is "('string')". Look at some of the other default values that are set in the metadata for an example. By the way, this might work for booleans too since they're really just numbers in the database. Create a default of 0 for false, or 1 for true and see what happens.

You do need to regenerate the views and triggers. The schema manager will do this for you when you add a new attribute. Unfortunately, it won't do it any other time. But, if you run the p_genSpecificViewAndTriggers with the base table name (say, LeadBase, for leads) as that parameter, you'll get the SQL necessary to recreate the bits. You need to run the sproc, copy the output, paste it to a new SQL QA window, and run it in the orgname_MSCRM database.

This is off the top of my head. It's 100% unsupported. And it may not work. I suggest creating a backup before mucking about in the databases because if you break it following something I say here, the support team will not help you.