docs.intersystems.com
Using Zen Components
Query Parameters
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Search:    

Query Parameters
When you are working with SQL queries to generate the data for a Zen table, you sometimes need to provide values for query input parameters, defined as ? characters within the query. To do this, use <parameter> elements within the <tablePane> element. <radioSet>, <select>, <dataListBox>, <dataCombo>, <repeatingGroup>, and <multiSelectSet> can also contain <parameter> elements to support queries.
Attribute Description
value
Specifies the parameter value:
The value supplied for a parameter can be a literal string, or it can contain a Zen #()# runtime expression.
When you supply a query directly, as with a sql attribute, each <parameter> element substitutes for one ? in the query syntax, in order from left to right, even if the values are the same. For example:
<tablePane id="table"
           sql="SELECT ID,Name FROM MyApp.Employees
                WHERE Name %STARTSWITH ? AND 
                ((Salary &lt; ?) OR (TotalCompensation &lt; ?)) 
                ORDER BY Name"
           >
     <parameter value="Z"/>
     <parameter value="100000"/>
     <parameter value="100000"/>
</tablePane>
The Data Sources section in this chapter provides several other examples of how to use the <parameter> element, including the following class query example. Here each <parameter> element substitutes for one argument in the class query:
<tablePane id="table"
           queryClass="MyApp.Employee"
           queryName="ListEmployees">
    <parameter value="Sales"/>
    <parameter value="NEW YORK"/>
</tablePane>
When you work with %ZEN.Component.tablePane programmatically, If you are using one of the classes <radioSet>, <select>, or <multiSelectSet>, which do not implement the setProperty, you must first set an id for the parameter:
<parameter value="Sales" id="param1"/>
The following example changes the value of the first parameter to Finance, re-executes the query on the server, and updates the contents of the tablePane to display the new results:
 ClientMethod changeParams() [ Language = javascript ]
 {
     // find the tablePane component
     var table = zenPage.getComponentById('table');
     var param1 = zenPage.getComponentById("p1");
     param1.value='Finance';
     table.executeQuery();
 }