Export (0) Print
Expand All


banner art

[Applies to: Microsoft Dynamics CRM 4.0]

A picklist contains several options. Each option has the following attributes:

DataValue The index value of the selected option.
TextThe text of the picklist option.

The following properties and methods are available:

Picklist properties and methodsTypeDescription
{Field}.DataValuestringGet/set property

Get returns a string representation of the value of the selected option. You can use the method parseInt() to safely convert this to an integer value.

Set changes the selection to the value specified.

{Field}.SelectedTextstringGet property

Returns the string value of the selected option.

{Field}.GetSelectedOptionoptionPicklist option

Returns a Picklist option.

{Field}.Optionsarray of picklist optionsGet/set property

Get returns an array of Picklist option objects.

Set defines a new set of options, specified by an array of Picklist option objects.

{Field}.AddOption(Text, DataValue)optionUsed to add an option to the end of the current control's collection.

Text - a string value to be displayed in the option.

DataValue – an integer value that represents the index of the option.

Text and DataValue cannot be Null.

Data is used for storing arbitrary data on the picklist object.

To define valid options, you must modify the Attribute definition by using the Customization tools or the metadata APIs. You should not create new picklist options programmatically in form event code. Manipulating the Options array is the most common solution to ensure valid picklist data.

{Field}.DeleteOption(value)integerUsed to delete the option specified by value from the control's option collection. Does nothing if the option does not exist.
{Field}.DefaultValueintegerGet/set property.

Get returns the default value for the picklist.

Set specifies the default value for the picklist.


All the valid picklist options are defined in the Microsoft Dynamics CRM Metadata. When a record is saved with an invalid picklist option selected the field will be set to the default value and the invalid data will be lost.

There are two supported methods for retrieving the current selection for a picklist field as shown here.

The following returns the text value of the selected picklist item.


The following returns the index of the selected picklist item.



The following code example shows how to use a field of type Picklist. Note that when you add an option to a Picklist, the option must already exist in the set of possible options.

var oField = crmForm.all.SOME_PICKLIST_FIELD_ID;

// Capture the fourth option
var oOption = oField.Options[4];

// Show how many options are available
alert("Original length :"+ oField.Options.length);

// Set the field to the first option by value
oField.DataValue = 1;

// Show the text for the first option

// Remove the fourth option

// show the new length
alert("New length :"+ oField.Options.length);

// Restore the fourth option
oField.AddOption(oOption.Text, oOption.DataValue);

// Show the restored length
alert("Restored length :"+ oField.Options.length);

See Also


Other Resources

© 2010 Microsoft Corporation. All rights reserved.

© 2014 Microsoft