Caché QuickStart Tutorial
Displaying the Phone Numbers
[Back] [Next]

We have to do a bit more work to display the phone numbers on our Zen page than we had to do to display the address. This is because we designed the database schema to store the phone numbers separately from the contacts. In order to display the phone numbers we must add another Zen GUI component like we did for the addresses. In addition, however, we must provide the logic for retrieving the phone numbers and displaying them on the page. The code generated by the wizard will not automatically handle the phone numbers.

Here is a summary of the changes we must make:
Here are the steps:
  1. First, add the following <textarea/> element to the XDATA Contents block of the Zen page. Place it after the <text/> elements that you added to display the address.
    <textarea id="PhoneNumbers" name="PhoneNumbers"  label="PhoneNumbers" title="Enter a value"  cols="25" height="23" />
  2. Next, add the following method to ContactForm. Place it anywhere in the class definition.
    Method GetPhoneNumbers(id As %String) [ ZenMethod ]
     Set tContact = ##class(ContactDB.Contact).%OpenId(id)
     Set PhoneNumbers=""
     If $IsObject(tContact) {
       for i=1:1:tContact.PhoneNumbers.Count()
       if (PhoneNumbers '= "")
       Set PhoneNumbers 
        Set PhoneNumbers 
     Do %page.%SetValueById("PhoneNumbers",PhoneNumbers)
    There are several interesting things to note about this method:
  3. Finally, we must add a line of code to the getRecord method. This method was originally generated by the Zen Form wizard. Find getRecord in the ContactForm definition and add the following line of code to the end of the method body.
    This line of code uses the zenPage special variable to invoke our GetPhoneNumbers method; passing it the id of the contact to be displayed on the form.
    With the new line of code, the method looks like this.
    ClientMethod getRecord(id As %Integer) As %Status [ Language = javascript ]
     var controller = zen('mvc');
     var idText = id.toString();
     zenPage.MyId = idText;
     var id = zen('ID');
     //line added to support display of phone numbers
    Note the following about this method:
For more information about ZenMethod, ClientMethod, and the different kids of Zen methods, please read Zen Methods on Client and Server in the Zen Pages section of Developing Zen Applications.
For more information about %page,zenPage, and other Zen special variables, please read Zen Special Variables in the Zen Pages section of Developing Zen Applications.