FAQ/applying-hidden-filters-programmatically.md
... ...
@@ -9,7 +9,11 @@ Sometimes a situation arises where using the hidden filters collection will not
9 9
```csharp
10 10
public override void PreExecuteReportSet(ReportSet reportSet)
11 11
{
12
- if (reportSet.IsDashBoard)
12
+ bool isRenderingToVisualization = false;
13
+ try
14
+ { isRenderingToVisualization = (bool)reportSet.GetVolatileOption("VisualizationRendering"); } //Get the flag for whether this ReportSet is being used as source data for a visualization on a dashboard.
15
+ catch { }
16
+ if (reportSet.IsDashBoard && !isRenderingToVisualization)
13 17
{
14 18
Report myReport = reportSet.Reports[0]; //This report will always represent the dashboard tile currently being handled by the system.
15 19
Filter newFilter = null;
... ...
@@ -20,6 +24,7 @@ public override void PreExecuteReportSet(ReportSet reportSet)
20 24
}
21 25
else
22 26
{
27
+ //This case is used for the report viewer and for source data for visualizations on dashboards.
23 28
Filter newFilter = null;
24 29
if (FilterCanBeAddedToReport(reportSet.JoinedTables, out newFilter))
25 30
{
... ...
@@ -36,7 +41,7 @@ public bool FilterCanBeAddedToReport(JoinedTableCollection jts, out Filter newFi
36 41
{
37 42
foreach (Column col in AdHocContext.Driver.DatabaseSchema.Tables[jt.DbTable.FullName].Columns.AllValues)
38 43
{
39
- if (col.FullName.ToLower().Contains("CustomerID".ToLower())) //replace "Customer_ID" with the column name to check for. If there is other criteria that must be met, then add that information into this if statement
44
+ if (col.FullName.ToLower().Contains("CustomerID".ToLower())) //replace "Customer_ID" with the column name to check for. If there is other criteria that must be met, then add that information into this if statement.
40 45
{
41 46
newFilter = new Filter(col.FullName);
42 47
newFilter.Hidden = true;
... ...
@@ -53,13 +58,19 @@ public bool FilterCanBeAddedToReport(JoinedTableCollection jts, out Filter newFi
53 58
54 59
```visualbasic
55 60
Public Overrides Sub PreExecuteReportSet(ByVal reportSet As ReportSet)
56
- If reportSet.IsDashBoard Then
61
+ Dim isRenderingToVisualization As Boolean = False
62
+ Try
63
+ isRenderingToVisualization = reportSet.GetVolatileOption("VisualizationRendering") 'Get the flag for whether this ReportSet is being used as source data for a visualization on a dashboard.
64
+ Catch
65
+ End Try
66
+ If reportSet.IsDashBoard AndAlso Not isRenderingToVisualization Then
57 67
Dim myReport As Report = reportSet.Reports(0) 'This report will always represent the dashboard tile currently being handled by the system.
58 68
Dim newFilter As Filter = Nothing
59 69
If FilterCanBeAddedToReport(myReport.JoinedTables, newFilter) Then
60 70
myReport.Filters.Add(newFilter)
61 71
End If
62 72
Else
73
+ 'This case is used for the report viewer and for source data for visualizations on dashboards.
63 74
Dim newFilter As Filter = Nothing
64 75
If (FilterCanBeAddedToReport(reportSet.JoinedTables, newFilter)) Then
65 76
reportSet.Filters.Add(newFilter)
... ...
@@ -72,7 +83,7 @@ Public Function FilterCanBeAddedToReport(jts As JoinedTableCollection, ByRef new
72 83
newFilter = Nothing
73 84
For Each jt As JoinedTable In jts
74 85
For Each col As Column In AdHocContext.Driver.DatabaseSchema.Tables(jt.DbTable.FullName).Columns.AllValues
75
- If col.FullName.ToLower().Contains("CustomerID".ToLower()) Then 'replace "Customer_ID" with the column name to check for. If there is other criteria that must be met, then add that information into this if statement
86
+ If col.FullName.ToLower().Contains("CustomerID".ToLower()) Then 'replace "Customer_ID" with the column name to check for. If there is other criteria that must be met, then add that information into this if statement.
76 87
newFilter = New Filter(col.FullName)
77 88
newFilter.Hidden = True
78 89
newFilter.Value = "BONAP"