Skip to main content

Determining the Number of TicketItems

Next, we are going to show some information about each order item.

We start by retrieving the TicketOrder object from the database using the Object ID stored in the %session object and assigning its oref to the variable ord. We use a line of Caché code to do this.

Whenever we want to use Caché code in a Web page, we simply enclose it within a standard <script> tag. The runat attribute indicates that the code runs on the server, not in the browser.

Now that we have a TicketOrder object, we can set up a loop to show each TicketItem. The number of iterations for the loop is determined by calling the method ord.Items.Count, which returns the number of TicketItem instances.

—Order.csp—
Order.csp
 <html> <head></head>
<body>
<csp:class super="%CSP.Page,Cinema.Utils">
<csp:if condition='$D(%session.Data("Order"))'>
    <img src="YourTicketOrder.gif"><br>
    <script language="cache" runat="server">
        // Open Order object for display
        Set ord = ##class(Cinema.TicketOrder).%OpenId(%session.Data("Order"))
    </script>

    <csp:loop counter="num" from=1 to=#( ord.Items.Count() )#>
        . . .
    </csp:loop>
</csp:if>
</body> </html>
FeedbackOpens in a new tab