Advanced filtering

From Resco's Wiki
Jump to navigation Jump to search

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

  1. Enable the Primary Contact field on the Account entity. See managing fields for instructions.
  2. 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.
  3. Click Edit Filter to open the Filter editor.
    1. Click Add Condition.
    2. Select Customer as field.
    3. Select Equals as operator.
    4. Click Variable and select the Account entity and the Id field.
    5. Click OK, then click Save & Close to close the filter editor.
  4. Open the Account’s form and add the Primary Contact field to the form. See adding fields for instructions.
  5. 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.

  1. Add the field Primary Contact to the Account form.
  2. Select the field and click Properties.
  3. On the Lookup Views pane, click Edit Filter.
  4. Add the necessary filter condition.

Example of adding filter to lookup view

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.