This documentation is archived and is not being maintained.


banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

A Lookup field type represents the relationship attribute on the related entity. The valid type for the lookup is established in the relationship. Although Lookup is frequently used as a generic term, there are different types of lookups and technically Lookup is the most restrictive kind of field type. Unlike Customer or Regarding, only one entity type is valid in a lookup. Unlike PartyList, only one reference is stored in the field. A lookup field is defined by using the following attributes:

idStringThe GUID of the item. Required for set.
typeIntegerDeprecated. The entity type code.
typenameStringThe entity name of the item. Required for set.
nameStringThe name of the item to be displayed. Required for set.
data Any other data. Optional for set.

The following properties are available:

Lookup propertiesTypeDescription
{Field}.DataValueAn array of lookup objectsGet/set property.

For lookups this must be an array with the length of one. DataValue is Null when no value is selected. Set DataValue to Null to make the lookup field blank.


The following code example shows how to read values from a field of type Lookup.

var lookupItem = new Array;

// This gets the lookup for the attribute primarycontactid on the Account form.
lookupItem = crmForm.all.primarycontactid.DataValue;

// If there is data in the field, show it in a series of alerts.
if (lookupItem[0] != null)
   // The text value of the lookup.

   // The GUID of the lookup.

   // The entity type name.



The following code example shows how to set values in a field of type Lookup. This example shows how to set the parent account lookup field on the account form.

//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object. = '{1AAC1363-01A1-DB11-8432-0003FF9CE217}';
   lookupItem.typename = 'account'; = 'A Bike Store';
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.parentaccountid.DataValue = lookupData;

See Also


Other Resources

© 2010 Microsoft Corporation. All rights reserved.