Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Next, we will add a drop down that displays the list of orders for a particular customer. When the user selects a customer name from the first drop down, we will display the list of orders for that customer from the database. This is essentially repeating the steps above except that the database query is triggered by a user action (selecting a customer from the drop down) and depends on the selected customer.

Define a query

Add Here is the following query to used in the built-in configuration file. Note that, this query requires a parameter indicated by the {cnum}.

Code Block
<query name="ordersByCustomer" autocreate="true">
            <retrieve>
     <!--maps to HTTP GET -->           <statement>
                    SELECT "orderNumber", "orderDate", "status", "customerNumber" FROM "Orders
      " WHERE "customerNumber"={cnum} ORDER BY "orderDate"
                </statement>
            </retrieve>
</query>

Modify the form

...

Code Block
/*member orderDate, orderNumber, resultSet */ 
var x; 
 
if (sc.value.length > 0) {
  eval ('x=' + http.get('http://localhost:8082/database/BIRT/ordersByCustomer?cnum=' + sc.value));
  var opts= [];
  for (var i=0; i < x.resultSet.length; i++) {
    if (x.resultSet[i]) {
      opts[i] = x.resultSet[i].orderNumber + '=' + x.resultSet[i].orderNumber + ': Date ' + x.resultSet[i].orderDate;
    }
  }
  so.options = opts;
}

Let's analyze this rule.

  1. if (sc.value.length > 0) - this implies that the rule will execute when the select customer drop down has a value and the value changes.
  2. eval ('x=' + http.get('http://localhost:8082/database/BIRT/ordersByCustomer?cnum=' + sc.value)) - this causes an HTTP GET. We pass the selected customer number as the value of cnum to the query.
  3. The rest of the rule is essentially identical to the previous rule. For the label we concatenate order number and order date.

...

Since order details is a complex structure (product name, quantity, price etc.) we will use 's built-in XML features to generate controls and populate them from the database. When an order is selected, the order line items will be displayed as shown below:

Define a query

As always, we must first define a query in the Here is the query defined in the built-in configuration file. The query requires a parameter indicated by {onum}.

Code Block
<query name="orderDetailsByOrder" autocreate="true">
            <retrieve>
     <!--maps to HTTP GET -->           <statement>
                    SELECT p."productName" as "product", o."quantityOrdered" as "quantity", o."priceEach" as "price", p."productDescription" as "description", p."MSRP"
                p.productDescription as description, p.MSRP FROM "OrderDetails" o, "Products" p WHERE
                    WHERE o."productCode"=p."productCode" and o."orderNumber"={onum} 
                    ORDER by o."orderLineNumber"
                </statement>
            </retrieve>
</query>

Generate XML schema

...