Friday, August 19, 2011

The CRM 2011 SDK is wrong (ish)

So that might be a slight exaggeration, but I just hate it when documentation is incorrect. In this situation, the culprit is the javascript to assign a value to a lookup field. According to the SDK, there are 3 properties you must set on your array to set the value on a lookup:
  • id
  • name
  • entityType
Unfortunately, if you try to set these three properties and then use the setValue() method to assign it to a lookup, you will either get nothing or an error stating that the "object does not support this property or method". That's because "entityType" doesn't actually exist.

Instead, you must create your array, same as before, but set the id, name, and type. Just "type". Set this to the object type code for the entity (1 for account, 2 for contact, 8 for user, etc.) and suddenly the setValue() actually sets something.

EDITED TO ADD:
So it seems I am only half correct. Upon reading the SDK more closely, it seems you CAN set entityType, but it should be a string for the entity instead of the type code. Got so used to the type codes in 4.0.... Anyway, if you set entityType to something like "account" or "systemuser" then it works.