Let us see how to sort a lookup field in a custom order in Dynamics 365.
Sorting makes it easy for us to get a quick overview of the data. For example, if we have many customers, we could sort them by Customer No., Currency Code, or Country Region Code to get the overview we need.
Consider a scenario, on a Work Order we have Incident Type and the values in the lookup sort based on the primary field. We must sort the Incident Type records based on the priority.
We have to create a field for priority which can be either Single Line of Text or Whole Number.
Navigate to Advanced Settings -> Customize the System
Expand the required entity and select Fields and create a new field.
Then add the field on to the form to provide the Priority.
For lookup values, there is by default a view is created “<Entity Name> Lookup View”, here in our scenario Incident Type Lookup View.
Open the Incident Type Lookup View and from Add Columns, select the Priority field which is created.
Sort the view on Priority either in Ascending or Descending order based on the requirement.
Click -> Configure Sorting -> provide Sort By and Select either Ascending or Descending
Now open the form where we want to sort the Lookup value.
In the Field Properties, Under Display tab turn off recently used items.
Configure the Default View as the view we have configured, Incident Type Lookup view.
Save and Publish the Customizations.
Now in the form we can see the Sorting order of the Incident Type Lookup view based on the Priority.
Other way round to achieve this is adding a prefix to the records, e.g.,
- 1 – Test & Inspect
- 2 – Support – Phone
- 3 – Internal