How to Work with Lookup Form Controls

banner art

You can read values from, and set new values to, almost all of the Microsoft CRM form controls, including lookups.


This sample code demonstrates how to read values from a primarycontactid lookup control on an account form.

var lookupItem = new Array;

// Get the lookup for the primarycontactid attribute 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)
    // Display the text value of the lookup.

    // Display the entity type name.

    // Display the GUID of the lookup.

    // Display the entity type code of the lookup. A value of 1 equals account, and a value of 2 equals contact.


This sample code demonstrates how to set a value to a pricelevelid lookup control on an opportunity form. In this example, the price level is set to Retail.

// Create a lookupItem to store the values that you want to set to a target lookup control.
var lookupItem = new Array();

// Specify the values on the signature of LookupControlItem. These values are the GUID of pricelevel, the type code of pricelevel, and the name of the lookup value.
lookupItem[0] = new LookupControlItem ("{F31BB38A-0EC0-403F-99A6-3AF469D7D76E"}, 1022, "Retail");

// Set the form control value to the lookupItem that you just created.
crmForm.all.pricelevelid.DataValue = lookupItem ;

© 2007 Microsoft Corporation. All rights reserved.