The advantage of modifying a Results section filter is that it excludes data from the display without affecting the local data set and without a database connection. Processing Query section limits requires a database connection.
There must be a limit on the Limit Line for the script to execute. If there is no existing limit, an “uncaught exception” error will be recorded in the Console window and the rest of the script will not execute. |
This exercise assumes that the Script Editor for the drop-down box drp_Territory is open. If it is not, open the file Sample1mod.bqy and activate the Limits Dashboard section. In Design mode, select the drop-down box drp_Territory, and then right-click to select Scripts. |
To modify an existing limit with the drop-down selection:
Delete the Alert line in the existing JavaScript.
There should be one statement left in the scripting frame.
var Selection=drp_Territory.Item(drp_Territory.SelectedIndex);
Use the Object browser to navigate to Application ), then ActiveDocument, then Sections, then Limits Results, then Limits, then 1, then SelectedValues, then Methods and then double-click RemoveAll.
The Limits Results section is low in the object model hierarchy because it is the result of a second query (every section that pertains to the first query comes before it).
The RemoveAll method deletes any current values, making “room” for the new selection.
Type a semicolon (;) at the end of the statement, and then press [Enter].
ActiveDocument.Sections["Limits Results"].Limits[1].SelectedValues.RemoveAll();
JavaScript recognizes an end-of-statement when it sees a return [Enter] or a semicolon (;). It is good practice to end statements with both, especially when a long line wraps and starts looking like several lines in the Script Editor.
Add the user’s selection as the next statement in the script.
Double-click the Add method (in the same Methods folder as RemoveAll).
Type the variable Selection as the argument for Add (inside the parentheses).
Type a semicolon (;) at the end of the statement, and then press [Enter].
ActiveDocument.Sections["Limits Results"].Limits[1].SelectedValues.Add(Selection);
This step adds the selection the user chose as the value for the limit.
For the next statement, add the limit operator.
Navigate up the object model to object 1, expand the Properties folder, and then double-click Operator.
The Intelligence Client object model includes a collection of Constants. Use the BqLimitOperator constant to set the Operator value in the next step.
In the object model Constants collection, open BqLimitOperator, and double-click bqLimitOperatorEqual.
You may want to close all expanded folders to access Constants more easily.
End the statement with a semicolon (;) and a return [Enter].
ActiveDocument.Sections["Limits Results"].Limits[1].Operator=bqLimitOperatorEqual;
Double-click the Recalculate method from ActiveDocument, then Sections, then Limit Results, then Methods.
ActiveDocument.Sections["Limits Results"].Recalculate()
The Recalculate method instructsInteractive Reporting to recalculate the results data. It takes no arguments, but still has parentheses because it is a method.
Toggle to Run mode and select a different item in the drop-down box.
In Run mode, selecting an item in the drop-down box changes the limit value and operator, and recalculates the results to include data for a Territory equal to the selection. The pie chart updates with the current results data.