Monday, January 24, 2011

Javascript & Read-Only Picklists

So you've got this great bit of Javascript that changes a read-only picklist field. Great! The only problem is, when the code fires on an update form, the picklist that you set doesn't get saved! It'll work on create, so whats the deal?

What you need to do is go back into your Javascript and enable the "ForceSubmit" attribute of the picklist. For example (from CRM 2011, changing one picklist based on the value of another picklist onchange):

function CheckType() {
  if(crmForm.all.new_type.DataValue == 100000001) {
    crmForm.all.new_readonlypicklist.DataValue = 100000001;
    crmForm.all.new_readonlypicklist.ForceSubmit = true;
  }
}

Your picklist field should now update and save properly!

Sunday, January 23, 2011

Simple CRM FetchXML in C#

Need to use some FetchXML in C# to pull some data? Normally you would have to write your FetchXML, then worry about paging since you may have more than 5,000 records. Luckily, there's an easy way to speed up both of these processes.

Use this tip from Rockstar Bits & Ronald Lemmen to generate your FetchXML automatically from an advanced find:
http://rockstarbits.blogspot.com/2010/02/using-advanced-find-to-generate.html

Next, use this sample from Phil's CRM Blog which gets rid of the paging hassle:
http://blog.expertsoftware.co.uk/post/2009/03/19/Retrieving-All-Records-with-Fetch-XML.aspx

Now that you've got your results, load them into an XmlDocument for parsing and away you go!