Applying a Filter to a Search Dialog

There are times when only a handful of items make sense for a specific Item property. In these cases, you’ll likely want to avoid any potential confusion and display only those items in the results of the Search Dialog. Today we’ll be going over an example on how to ensure that only Admin Identities can be picked for an Identity Item property.

Getting Started

You can find all of the code for this project in the search-filtered-item-browser project on the Aras Labs GitHub.

ArasLabs/search-filtered-item-browser

Note: While this project was built using 11.0 SP12, it should be compatible with any older service pack of 11.0 .

Setting Up The Scenario

We’ll begin by creating a new ItemType called Search Filter Example. We’ll also add a single property with the following information.

  • Name – filtered_property
  • Label – Filtered Property
  • Data Type – Item
  • Data Source – Identity

Let’s add this ItemType to the TOC and give ourselves permissions to add and update these items under the Can Add and Permissions relationship tabs respectively. We’ll save our new ItemType and open our Property by right-clicking on it and selecting View “Properties”.

In the Event relationship tab of this Property, we’ll create a new Event and set the Event property to onSearchDialog. This will call our filtering method each time the Search Dialog for this property is opened. Now let’s right-click and select View “Method to open up the method editor.

Writing Our Filter

In this example, we only want to display Admin Identities to our user. To further the example, we’ll also limit our results to only Alias Identities. With these two criteria in mind, the code for our filter should look something like below.

Now let’s go to our new ItemType in the TOC and create a new Search Filter Example. When you click the search button next to the Item field, you’ll notice that the search criteria we’ve specified are automatically loaded in to the dialog. Running our search, we’ll also see that only Identities whose names end in ‘Admin’ are returned.

This is great, but we’re missing the Super User Identity. In a Search Dialog, we could include the Super User Identity in our search by using criteria like ‘%Admin|Super User’. However, it is not currently possible to include the OR operator (‘|’) in our filter criteria at this time. We have two alternative methods of filtering to work around this issue.

Filter By ID

The first workaround is to perform a search within our onSearchDialog event to get the IDs of the items that match our criteria. We can then pass a list of these IDs into our Search Dialog to display only those items. We can do this with code like the example below.

After copying this code into the onSearchDialog method you created earlier, you’ll need to close and reopen the Search Filter Example. Now when we open the Search Dialog for our property, we’ll notice that the Super User Identity is returned in addition to our Admin Identities. However, it is not possible to edit the search criteria in this example. We can use one other way of filtering to to allow our users to change the criteria from what’s specific in our filtering method.

Filter By AML

We can also directly pass in the AML of a query we want to filter our results by. The code below shows how we can accomplish this.

By opening our Search Dialog again, we can see that this way of filtering both supports an OR operation as well as supports the ability to manually edit the search criteria after the filters are applied.


LOOKING FOR MORE ARAS INSPIRATION?

Subscribe to our blog and follow @ArasLabs on Twitter for more helpful content! You can also find our latest open-source projects and sample code on the Aras Labs GitHub page.

4 thoughts on “Applying a Filter to a Search Dialog

  1. AngelaIp

    Hi, thanks for the helpful article! But of course I wouldn´t write without having a question 🙂
    Does the search dialog filter also work, when I just use type-ahead as input and avoid the search dialog?

Leave a Reply