Set Lookup Value using JavaScript Tip

Everyone has seen the method of updating a CRM lookup field on a form, most examples look something like this.

// CRM 4
var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].typename = typeValue;

crmForm.all.fieldName.DataValue = value;

// CRM 2011
var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].entityType = typeValue;

Xrm.Page.getAttribute("fieldName").setValue(value);

How about doing it on one line like this instead.


// CRM 4
crmForm.all.field.DataValue = [{id: idValue, name: textValue, typename: typeValue}];

// CRM 2011
Xrm.Page.getAttribute("fieldName").setValue( [{id: idValue, name: textValue, entityType: typeValue}]);

There is a short but interesting article about JavaScript called Seven JavaScript Things I Wish I Knew Much Earlier In My Career by Christian Heilmann if you have some spare time to read.

Latest Microsoft CRM 4.0 Rollup = 10

Update Rollup 10 for Microsoft Dynamics CRM 4.0 is available.

Microsoft CRM 4.0 Rollup 10 is here (8th April 2010) and information about the Rollup is here.

Address Lookup Dialog

Have you noticed when searching for a customer address using the built in Address dialog that only addresses with a Name value are returned. I’ve had instances where the default address name field has been used as House Name and as we all know not all houses have a name.

If you have look at the code that is used to open the Address Lookup it calls an aspx page named lookupsingle.aspx and passes a querystring parameter ‘class’ with a value of ‘BrowserCustomerAddress’. BrowseCustomerAddress is the title of an xml file found in the ‘Microsoft Dynamics CRM\Applications Files’ folder as BrowseCustomerAddress.xml. This file contains the query elements that the Address dialog uses to retrieve the specific customer addresses. A number of fields and also 3 conditions exist in this file and you will notice that one condition relates to the name field with an operator value of not-null. If you remove this condition node from the xml file, save it and then test your address dialog, you will now see all of the addresses for a customer. This is unsupported so only perform this if absolutely necessary and your aware of the implications.

To reuse the Address dialog on your own entities or where the Address Lookup is not available , for example to fill custom address fields on a Case, then Dave Berry has a good example here of how to utilise the standard MSCRM Address Lookup dialog for your own use.

For a more customised approach then there is an MSDN article here on how to retrieve data for a related entity, in this case it demonstrates retrieving addresses.