The following is a quick explanation for how to create a report Filter using the .NET Api.
Ensure that your application is referencing the Filter class, which is located in the WebReports.Api.Reports namespace, and the DataValue class, which is located in the WebReports.Api.Common namespace.
/* Manually Creating a Filter */
Filter myFilter = myReport.Filters.NewFilter();
myFilter.Name = "Categories.CategoryName";
myFilter.Operator = wrFilterOperator.NotOneOf;
myFilter.AndOrWithNext = wrFilterAndOrWithNext.And;
myFilter.GroupWithNext = false;
myFilter.Prompt = false;
DataValue condiments = new DataValue(myApi.PageInfo, 0);
condiments.Value = "Condiments";
DataValue produce = new DataValue(myApi.PageInfo, 0);
produce.Value = "Produce";
NOTE: Filters created in the API are unique to their session.
Use the convenience method, myReport.Filters.NewFilter() to create a new filter in the report. Then set the following fields:
NOTE: myReport.Filters is an ordered list of filters. To change the order of precedence, re-order the list and use the filters' grouping variables to create precedence groups.
myFilter.Name - The mnemonic entity and column name to filter on.
myFilter.Operator - Accepts one of the following wrFilterOperator enumerators for the filter operator type:
- Between (two vars)
- NotBetween (two vars)
- OneOf (one or more vars)
- NotOneOf (one or more vars)
myFilter.AndOrWithNext - How this filter groups with the next filter. Accepts a wrFilterAndOrWithNext enumerator.
myFilter.GroupWithNext - Whether or not to group this filter with the next filter, in order to control for the order of operation. Accepts true or false.
myFilter.Prompt - Whether or not this filter prompts for a value upon report execution. Accepts true or false.
If you're using a single variable operator, then set the filter value and data type with the following calls:
myFilter.Type - Accepts an integer representing the data type:
- 0 - string
- 1 - date
- 2 - integer
- 3 - decimal
If you're using a multi variable operator, then you'll need to create a DataValue object for each value to add to the filter. Use the following constructor:
myDataValue = new DataValue(myApi.PageInfo, dataTypeInt);
The DataValue constructor requires the API's PageInfo as the first argument, and an integer representing the data type (see myFilter.Type above) as the second.
Then set the data value:
And add it to the filter's list of data values: