Often when designing a form for an entity, you want to include a lookup field to another entity, where the user can select from a list of records. However, sometimes you need to restrict which items to display. For example, a single account may have multiple associated contacts, however, only one contact can be designated as primary. When you add the field Primary Contact to the Account form, users should be able to select only from the associated contacts, not from the full contact list.
You have two options for accomplishing this: Create a new view and use it for the lookup, or use an existing view with an additional filter.
Both solutions are valid.
- When you create a custom view, you have the benefit that you can create a custom style/format of the view; perhaps omitting fields that are unnecessary in the context of the lookup. You can also make all your lookup views have the same distinct style.
- Adding a filter to an existing view is a simpler and faster way, albeit without the style/format option.
Create dedicated lookup view
- Enable the Primary Contact field on the Account entity. See managing fields for instructions.
- Create a new view of the type Lookup List for the Contact entity. See creating a view for instructions.
Let’s name it “Account’s Contacts”. You can also check the Hidden option, so that it is not shown in the view selector in the Mobile CRM application. Add any desired fields to the Primary and Secondary fields.
- Click Edit Filter to open the Filter editor.
- Click Add Condition.
- Select Customer as field.
- Select Equals as operator.
- Click Variable and select the Account entity and the Id field.
- Click OK, then click Save & Close to close the filter editor.
- Open the Account’s form and add the Primary Contact field to the form. See adding fields for instructions.
- Select the new field and click Properties. On the Lookup Views pane, enable the new lookup view and make it the default view.
After you save the form, publish the project and attempt to choose the Primary Contact for an Account, you can only choose from the filtered selection displaying the Account’s contacts, not all contacts. You still have the possibility to change the Lookup view to the default one with all contacts, unless you disable the Default View on the Primary Contact properties.
Add filter to existing view
As an alternative, you can reuse an existing view and add a custom filter that will be used only in this context. If the existing view also includes a filter, both filters apply.
- Add the field Primary Contact to the Account form.
- Select the field and click Properties.
- On the Lookup Views pane, click Edit Filter.
- Add the necessary filter condition.
Advanced filtering in lists
The same function allows you to filter the records on the associated or unrelated lists. Double-click the list to display its properties and go to the Associated Views tab. Again, you have the same two options:
- Click Edit Filter to add filter to an existing view.
- Switch to a custom view from the list of views in the table.