Klevr Product Documentation logo

How To: Use Portal Filter Criteria

This guide describe how to use the Portal Filter Criteria entity correctly.

This guide describe how to use the Portal Filter Criteria entity correctly. It is intended for users that manage CE and portal configuration.

  • This guide assumes that you have sufficient knowledge and experiecne with advanced querying and fetchxml in CE.

Purpose

The purpose of the Portal Filter Criteria entity is to allow filtering of data on the portal based on specific user information. /A prime example is fund eligibility criteria, for instance you have to be of a minimum age for certain funds. Howver, the entity is created in a generic way so that you can adjust and add it to any other entity you see fit. There are a few things to keep in mind:

  1. If you use the filter criteria entity on a record, you have to use it on all records, due to the way fetchxml table linking works. This means you will likely have a "No restriction" filter criteria record, and this will need to be the default if no other criteria applies. The reason for this is that the portal query will be constructed in such a way to reaturn all records where the associated filter criteria is met, and if there are no associated filter criteria, the records will not be returned in the result.
  2. We have not added any standard filtering fields. You need to add the fields specific to your project. The reason for this is that when you construct the query, you will need conditions for all of the combinations of filters that can be applied, so the less combinations you have, the easier your query construction will be. More on this down below.
  3. To use the filter criteria, you need to add a lookup on the target table to the filter criteria table. By default we have only added it to the fund table.
  4. Security: The Grants administrator role has access to create and modify portal filter criteria (in the settings area of the grants app), and grants users only have the ability to read and associate them.

Detailed Instructions

This documentation will cover a single scenario where we want to have certain funds restricted to age, and certain funds restricted to a specific account type.

To start, we will add a minimum age, maximum age and account type fields to the Portal Filter Criteria entity, as part of the customer solution.

Next we will make the field available on the fund main form for user selection. You will need to make it mandatory, as all funds will need to be associated to a filter critera record.

Now we need to create some filter criteria records. See the table below for examples.

NameDescriptionSample Values
No Criteria (open)The default record where you do not want any criteria apppliedmin age: blank max age: blank type: blank
20 or overOnly contacts with an age of 20+ years can applymin age: 20 max age: blank type: blank
Between 20 and 60Contacts with age between 20 and 60 can applymin age: 20 max age: 60 type: blank
Account = MemberContacts associated to an account with type of member can applymin age: blank max age: blank type: member
Old MembersContacts over 40 with account type member can applymin age: 40 max age: blank type: member

From this you can hopefully see that building the query will not be straight forward, but doing it systematically as per the example, will ensure that it is correct for all situations.

Fetchxml Query

The fetchXml query needs to be constructed in such a way that it retrieves all funds across all criteria, taking blanks or null values into account. For instance, if we only had minimum age, the query would be find all funds where 'the related filter criteria's minimum age is blank' or 'the minimum age is met'. Where you have multiple fields to evalueate, you might need to extrapolate it to multiple clauses, so for our example above you need the following conditions:

Find all funds that has a related fund criteria where:

  • minimum age does not contain data and maximim age does not contain data and type does not contain data OR
  • minimum age contains data and minimum age is met, and maximum age does not contain data and type does not contain data OR
  • minimum age contains data and minimum age is met, and maximum age contains data and maximum age is met and type does not contain data OR
  • minimum age does not contain data and maximum age contains data and maximum age is met and type does not contain data OR
  • minimum age does not contain data and maximim age does not contain data and type contains data and type is met OR
  • minimum age contains data and minimum age is met, and maximum age does not contain data and type contains data and type is met OR
  • minimum age contains data and minimum age is met, and maximum age contains data and maximum age is met and type contains data and type is met OR
  • minimum age does not contain data and maximum age contains data and maximum age is met and type contains data and type is met

If you build business rules to force either age or type, but not both, you could reduce the number of statements above, but otherwise you will need to check for each combination to ensure whatever is created is queried correctly. You can construct a binary counting table to ensure you have everything. You should have 2 to the power of (number of criteria fields) conditions, in our example, we have 3 fields, so we have 2 to the power of 3 or 8 conditions:

TypeMaximum AgeMinimum AgeBinary (decimal)
blankblankblank000 (0)
blankblanknot blank and met001 (1)
blanknot blank and metblank010 (2)
blanknot blank and metnot blank and met011 (3)
not blank and metblankblank100 (4)
not blank and metblanknot blank and met101 (5)
not blank and metnot blank and metblank110 (6)
not blank and metnot blank and metnot blank and met111 (7)

so our fetchxml will look like this:

<fetch version="1.0" mapping="logical" no-lock="false" distinct="true">
    <entity name="klevr_fundinground">
        <attribute name="klevr_name" />
        <order attribute="klevr_name" descending="false" />
        <attribute name="statecode" />
        <attribute name="klevr_startdate" />
        <attribute name="klevr_fundvalue" />
        <attribute name="klevr_enddate" />
        <attribute name="klevr_fundingroundid" />
        <filter type="and">
            <condition attribute="statecode" operator="eq" value="0" />
        </filter>
        <link-entity name="klevr_portalfiltercriteria" alias="aa" link-type="inner" from="klevr_portalfiltercriteriaid" to="klevr_portalfiltercriteriaid">
            <filter type="or">
                <filter type="and">
                 <condition attribute="ws_minimumage" operator="null" />
                 <condition attribute="ws_maximumage" operator="null" />
                 <condition attribute="ws_type" operator="null" />
                </filter>
                <filter type="and">
                 <condition attribute="ws_minimumage" operator="lt" value="@self.ws_age" />
                 <condition attribute="ws_maximumage" operator="null" />
                 <condition attribute="ws_type" operator="null" />
                </filter>
                <filter type="and">
                 <condition attribute="ws_minimumage" operator="null" />
                 <condition attribute="ws_maximumage" operator="gt" value="@self.ws_age" />
                 <condition attribute="ws_type" operator="null" />
                </filter>
                <filter type="and">
                 <condition attribute="ws_minimumage" operator="lt" value="@self.ws_age" />
                 <condition attribute="ws_maximumage" operator="gt" value="@self.ws_age" />
                 <condition attribute="ws_type" operator="null" />
                </filter>
                <filter type="and">
                 <condition attribute="ws_minimumage" operator="null" />
                 <condition attribute="ws_maximumage" operator="null" />
                 <condition attribute="ws_type" operator="eq" value="@self.parentcustomerid.customertypecode" />
                </filter>
                <filter type="and">
                 <condition attribute="ws_minimumage" operator="lt" value="@self.ws_age" />
                 <condition attribute="ws_maximumage" operator="null" />
                 <condition attribute="ws_type" operator="eq" value="@self.parentcustomerid.customertypecode" />
                </filter>
                <filter type="and">
                 <condition attribute="ws_minimumage" operator="null" />
                 <condition attribute="ws_maximumage" operator="gt" value="@self.ws_age" />
                 <condition attribute="ws_type" operator="eq" value="@self.parentcustomerid.customertypecode" />
                </filter>
                <filter type="and">
                 <condition attribute="ws_minimumage" operator="lt" value="@self.ws_age" />
                 <condition attribute="ws_maximumage" operator="gt" value="@self.ws_age" />
                 <condition attribute="ws_type" operator="eq" value="@self.parentcustomerid.customertypecode" />
                </filter>
            </filter>
        </link-entity>
    </entity>
</fetch>

Last updated on