In the constant struggle to improve data quality it is common to avoid using free-text fields in favour of select fields. This approach has the advantage of ensuring that data is entered consistently such that it can easily be searched and reported upon.
There are a number of choices of approaches to implementing select fields in Dynamics CRM. This post aims to provide all the information you need to make an informed choice of which to use on a field by field basis. The options are:
Option-Sets are the default starting point for select fields.
No more than ~100 for performance reasons. All items are downloaded into the user interface which will cause performance problems for large lists – especially where there are lots of option-sets on the same form.
Requires JavaScript to filter items dynamically based on the user’s role/business unit.
Option-Sets require a metadata configuration change and a re-publish that would usually be done out of hours by an administrator. It is best practice to do this on a development environment and then import a solution into production. Adding new values to the list isn’t something that can be done by business users.
Removing items causes data loss in old records. Items can be removed using JavaScript to preserve old records, but Advanced Find will still show the values.
Each option-set item can be translated into multiple languages.
![]() |
If you need to have the select field multi-language then an option-set is probably your best choice unless it is going to be a long list, in which case you’ll need to make a compromise. |
Requires JavaScript to filter options.
It is not possible to store additional data other than the label and integer value of the option-set. You would need to store somewhere else in a lookup table format.
Use a global option-set that can be defined once and used by multiple option-set fields.
You can have as many select fields as your entity forms will allow. The more fields you have the slower the form will load and save.
Option-sets are always presented as a drop down in advanced fine and view filters.
Works across all clients including phone and tablet native apps.
![]() |
Option-sets are the most ‘native’ choice for select fields and will work in all deployment types without much consideration. |
Lookup fields allow selecting a single reference to a custom entity using a free text search.
Unlimited list items subject to database size. Since all list items are not downloaded to the user interface (unlike option-sets) the user can search quickly for the item they need.
Security Roles can be used in combination with a user owned lookup entity so that lookup records are visible to subset of users.
New records can easily be added by users using the ‘Add New’ link. Control over who can add new items can be done using Security Roles.
![]() |
If you need business users to add values regularly then a Lookup field is a good choice. The Configuration Migration tool in the SDK can be used to easily move values between environments. |
Old items can be easily deactivated and will no longer show in lookup fields (including in advanced finds) however existing records will retain their selected value (unlike when option-set items are removed).
![]() |
If you need to make changes constantly to the list and remove items without affecting previous records then a lookup field is most likely your best choice. |
Not possible without complex plugin server side code to dynamically return the name in the current user’s language.
Lookup filtering options can be added in the form field properties or can be added via JavaScript for more complex scenarios.
![]() |
Lookups are the easiest and quickest to setup dependant lists without writing code. This filtering will also work on tablet/mobile clients without further consideration. |
Additional information can be stored as attributes on the lookup entity records. Lookup views can show up to 2 additional attributes within the inline lookup control.
![]() |
If you are integrating with another system that requires a special foreign key to be provided, lookup entities are good way of storing this key. |
Lookups can easily be mapped between records using attribute maps/workflows or calculated fields.
CRM Online is limited to 300 custom entities.
![]() |
This is an important consideration and it’s unlikely to be a good idea to use Lookup entities for all of your select fields. |
![]() |
If you are using CRM online you’ll likely have to always use a combination of lookups and option-sets due to the limit of 300 custom entities. Don’t take the decision to make all your select fields as lookups. |
Lookups are presented as search fields in Advanced Find and Filters.
Works across all clients including phone and tablet native apps. If working offline however, all lookup values may not be available.
Autocompletes are a free text field with an on key press event added to show an autocomplete. The great thing about autocompletes is that they can show icons and additional action links.See below for an example of how to use autocompletes in Javascript.
An autocomplete field can only show as many items as you return at a time but you’ll want to put a limit for performance reasons.
![]() |
If you need the select field to be more like a combo-box where users can type their own values or select from predefined items then autocomplete text fields are a good choice. |
You can add any search filtering you need using JavaScript.
If the autocomplete is using a lookup entity to store the data displayed then the same considerations would apply as for Lookup Entities. If the values are hard coded into the JavaScript then this would be more akin to the Option-Set solution import.
Since the actual field is stored as a text field there is no issue with removing values. Existing data will still be preserved.
You can detect the user interface language and return a specific language field to the user via JavaScript however it will be stored in the textbox and other users will not see it in their language (unlike an option-set). One solution to this would be to use the autocomplete for data entry and then use a web resource to present the field value in the local user’s language.
You can apply whatever filtering you need using JavaScript.
If you use the autocomplete to search a custom entity you can store additional data as additional attributes. The autocomplete flyout can display multiple values for each result row.
![]() |
Autocomplete fields have the advantage that they can show an icon that is specific to the record (e.g. The flag of the country). If you need this feature, then Auto completes are a good choice. |
If you use a free text autocomplete it’s advisable to additionally populate a backing lookup field to facilitate searching/filtering. This would also allow you to ensure that ‘unresolved’ values cannot be saved by using an OnSave event to check that the text field matches a hidden lookup field that is populated in the OnChange event.
Autocomplete does not work on phone/tablet native apps yet.
I have added support for the Auto Complete SDK extensions in CRM2016 to SparkleXRM. To show a country autocomplete lookup, you’d add onload code similar to:
public static void OnLoad() { Control control = Page.GetControl("dev1_countryautocomplete"); control.AddOnKeyPress(OnCountrySearch); } public static void OnCountrySearch(ExecutionContext context) { string searchTerm = Page.GetControl("dev1_countryautocomplete").GetValue<string>(); string fetchXml = String.Format(@"<fetch version='1.0' output-format="xml-platform" mapping='logical' distinct="false"> <entity name="dev1_country"> <attribute name="dev1_countryid" /> <attribute name="createdon" /> <attribute name="dev1_name" /> <attribute name="dev1_longname" /> <attribute name="dev1_iso" /> <attribute name="entityimage_url" /> <order attribute="dev1_name" descending='false' /> <filter type="and"> <condition attribute="dev1_name" operator="like" value="{0}%" /> </filter> </entity> </fetch>", searchTerm); OrganizationServiceProxy.BeginRetrieveMultiple(fetchXml, delegate(object state) { try { // We use an aysnc call so that the user interface isn't blocked whilst we are searching for results EntityCollection countries = OrganizationServiceProxy.EndRetrieveMultiple(state, typeof(Entity)); AutocompleteResultSet results = new AutocompleteResultSet(); // The Autocomplete can have an action button in the footer of the results flyout AutocompleteAction addNewAction = new AutocompleteAction(); addNewAction.Id = "add_new"; addNewAction.Icon = @"/_imgs/add_10.png"; addNewAction.Label = "New"; addNewAction.Action = delegate() { OpenEntityFormOptions windowOptions = new OpenEntityFormOptions(); windowOptions.OpenInNewWindow = true; Utility.OpenEntityForm2("dev1_country", null,null, windowOptions); }; results.Commands = addNewAction; results.Results = new List<AutocompleteResult>(); // Add the results to the autocomplete parameters object foreach (Entity country in countries.Entities) { AutocompleteResult result = new AutocompleteResult(); result.Id = country.Id; result.Icon = country.GetAttributeValueString("entityimage_url"); result.Fields = new string[] { country.GetAttributeValueString("dev1_name"), country.GetAttributeValueString("dev1_iso"), country.GetAttributeValueString("dev1_longname") }; ArrayEx.Add(results.Results, result); } if (results.Results.Count > 0) { // Only show the autocomplete if there are results context.GetEventSource().ShowAutoComplete(results); } else { // There are no results so hide the autocomplete context.GetEventSource().HideAutoComplete(); } } catch(Exception ex) { Utility.AlertDialog("Could not load countries: " + ex.Message, null); } }); }
This would result in JavaScript:
ClientHooks.Autocomplete = function ClientHooks_Autocomplete() { } ClientHooks.Autocomplete.onLoad = function ClientHooks_Autocomplete$onLoad() { var control = Xrm.Page.getControl('dev1_countryautocomplete'); control.addOnKeyPress(ClientHooks.Autocomplete.onCountrySearch); } ClientHooks.Autocomplete.onCountrySearch = function ClientHooks_Autocomplete$onCountrySearch(context) { var searchTerm = Xrm.Page.getControl('dev1_countryautocomplete').getValue(); var fetchXml = String.format("<fetch version='1.0' output-format="xml-platform" mapping='logical' distinct="false">rn <entity name="dev1_country">rn <attribute name="dev1_countryid" />rn <attribute name="createdon" />rn <attribute name="dev1_name" />rn <attribute name="dev1_longname" />rn <attribute name="dev1_iso" />rn <attribute name="entityimage_url" />rn <order attribute="dev1_name" descending='false' />rn <filter type="and">rn <condition attribute="dev1_name" operator="like" value="{0}%" />rn </filter>rn </entity>rn </fetch>", searchTerm); Xrm.Sdk.OrganizationServiceProxy.beginRetrieveMultiple(fetchXml, function(state) { try { var countries = Xrm.Sdk.OrganizationServiceProxy.endRetrieveMultiple(state, Xrm.Sdk.Entity); var results = {}; var addNewAction = {}; addNewAction.id = 'add_new'; addNewAction.icon = '/_imgs/add_10.png'; addNewAction.label="New"; addNewAction.action = function() { var windowOptions = {}; windowOptions.openInNewWindow = true; Xrm.Utility.openEntityForm('dev1_country', null, null, windowOptions); }; results.commands = addNewAction; results.results = []; var $enum1 = ss.IEnumerator.getEnumerator(countries.get_entities()); while ($enum1.moveNext()) { var country = $enum1.current; var result = {}; result.id = country.id; result.icon = country.getAttributeValueString('entityimage_url'); result.fields = [ country.getAttributeValueString('dev1_name'), country.getAttributeValueString('dev1_iso'), country.getAttributeValueString('dev1_longname') ]; Xrm.ArrayEx.add(results.results, result); } if (results.results.length > 0) { context.getEventSource().showAutoComplete(results); } else { context.getEventSource().hideAutoComplete(); } } catch (ex) { Xrm.Utility.alertDialog('Could not load countries: ' + ex.message, null); } }); } ClientHooks.Autocomplete.registerClass('ClientHooks.Autocomplete'); });
Original Post https://develop1.net/public/post/2015/11/21/Option-Set-Lookup-or-Autocomplete