Business Rules / SQL

  "Soft" Filtering

Table of Contents
Business Rules / SQLPrint||
"Soft" Filtering

End users of Code On Time web applications have some impressible data filtering capabilities available to them. User-defined filters are also called “soft” filters. They can be canceled or activated at will.

Application developers can activate “soft” filters programmatically. For example, it may be appropriate to limit the amount of data in some data views based on a user identity or value of a session variable. Users can alter such “soft” filters on their own if a larger dataset is required.

Consider the Orders screen in the Northwind sample application.

A list of orders in the Northwind sample

An SQL Business Rule can be created to limit the list orders to those that meet a specific criteria without user intervention.

Select Orders data controller in Project Designer and enter a new business rule with the following properties.

Property Value
Command Name Select
Type SQL
Phase Before
Script
-- assign a filter if the client-side data view is not tagged
if @BusinessRules_Tags is null
begin
    -- tag the data view
    set @BusinessRules_Tags = 'Filtered'
    -- filter by Employee Name
    set @EmployeeLastName_Filter_Equals = 'Callahan'
    -- filter Ship Via Company Name by two values
    set @ShipViaCompanyName_Filter_Includes1 = 'Speedy Express'
    set @ShipViaCompanyName_Filter_Includes2 = 'United Package'
    -- assign a filter range to Freight
    set @Freight_Filter_Between1 = 10
    set @Freight_Filter_Between2 = 30
    -- assign a filter range to Order Date
    set @OrderDate_Filter_Between1 = '1/1/1998'
    set @OrderDate_Filter_Between2 = '6/1/1998'
    -- let the user know that the "soft" filter has been applied
    set @Result_ShowViewMessage = 'A "soft" filter has been applied.'
end

This is the data controller hierarchy after the rule has been saved.

A data controller with SQL Business Rule that executes before the data is selected

Generate the app and navigate to Orders page once more. A significantly shorter list of orders is rendered.

The "soft" filter produced by SQL Business Rule

A user can cancel some elements of the filter or apply a filter of their own. The script of the business rule assigns “Filtered” tag to the client-side data view to prevent interference with user actions.

The data view has a "soft" filtered assigned to it by the business rule

You can also assign a “soft” filter with business rules written in C# or Visual Basic .