It is very easy to give a default value to a picklist; however we need to pay attention on some specific setting in order to successfully generate the code. The following example shows how to set a default value to a picklist where we select a color.
-
Open Designer interface and create a picklist. Double-click the Picklist List on the left side of the Designer interface.
-
Obtain the Field Name and add some static values of color to the picklist, for example 'Red,' 'Blue,' 'Yellow,' 'Green' case-sensitive, which means that 'Red,' 'RED,' 'red' are different values
-
Open Script Editor and double-click AfterOpen event on the right side of the Editor.
- Add the following code into 'AfterOpen' event to set the picklist default value to 'Blue'
_FieldName.Value = "Blue"
where FieldName is our picklist's Field Name
Note: The default value that we set here MUST match one of the values in the picklist.