Wednesday, December 1, 1999

Developing a Palm VII PQA that reads data from a Domino database

.KEYWORD pqa
.FLYINGHEAD BUILDING WIRELESS APPLICATIONS
.TITLE Developing a Palm VII PQA that reads data from a Domino database
.OTHER
.AUTHOR Bruce Elgort
.SUMMARY The Palm VII is a very cool device. But to get data into it, a special Palm Query Application (PQA) must be written. In this important article, Bruce Elgort shows you how you can write your very own PQA. But that’s not all. If you use Lotus Domino, Bruce shows you how you can download Domino information directly into your Palm VII via a PQA of your own construction. Slick!
When I first purchased my Palm VII back in July, I thought that the applications that ran on the organizer required me to learn yet another development framework. I had heard that developing Palm OS applications wasn’t a trivial task. Much to my surprise, I learned that developing a Palm Query Application (PQA) to read data from a Lotus Domino database was a relatively simple process.

Don’t get me wrong, as the complexity of an application increases, so does the development of the PQA and back-end Web clipping processing files and scripts.

There are two parts to a Palm Query Application that you need to develop:

.BEGIN_LIST
.BULLET The Palm Query Application itself, which will reside on the Palm VII organizer.
.END_LIST

.BEGIN_LIST
.BULLET A CGI script, or in the case of Lotus Domino, a LotusScript or Java Agent that generates Web clippings using data from a Domino database. The Web clippings are sent back to the Palm VII as HTML.
.END_LIST

.CALLOUT You only clip the information you need and not all of the articles and photos on the page.

.H1 What is a Web clipping?
The term "Web clipping" is based on the analogy of clipping an article out of a newspaper; you only cut out or "clip" the information you need and not all of the articles and photos on the page. So when you as a developer are writing a PQA or an agent to generate a Web clipping, keep the user in mind and give them only what they asked for. Don’t give them any flaming logos!

Since the display of the Palm VII is limited in size, trying to display Web pages designed for an 800 by 600 dpi screen is impossible.

.H1 The Palm Query Application
The Palm Query Application is made up of one or more text files and graphics that are authored in a subset of HTML version 3.2. You can use WordPad or any text editor or HTML authoring tool to develop these files. These files then get compiled into a PQA using the Query Application Builder tool available from the 3Com Palm.Net Web site. A user can then use the HotSync utility supplied with the Palm VII and install the PQA on his or her organizer.

When developing PQAs, it’s important to remember that you aren’t developing Web pages for a fast Pentium PC with a 19" monitor and a 56kb modem. You’re developing Web pages for a monochrome device whose screen resolution is 153 by 144 pixels and communicates at an effective transmission speed of between 8kb/s to 19.2kb/s. You need to use the screen real estate effectively. PQAs are based on a simple query and response metaphor where the user enters and/or selects choices from the PQA and a discrete set of information is returned as a Web clipping to the user.

.H1 Which HTML features are not supported?
There are several HTML 3.2 tags that are not available to you when developing the PQA and Web clipping scripts. They are:

.BEGIN_LIST
.BULLET Image Maps;
.BULLET Animated GIFs;
.BULLET Cookies;
.BULLET Nested Tables;
.BULLET Frames;
.BULLET JavaScript;
.BULLET Java Applets;
.BULLET Style Sheets;
.BULLET Named Typefaces.
.END_LIST

.H1 A Simple PQA application
Many Notes developers have written a customer tracking database in Notes before. Since this article is intended to help Notes developers build PQAs, it seems reasonable to use such a customer tracking database as an example for this article.

Let’s take a look at a PQA that will return a list of customers from a simple customer tracking database using the Palm VII. The code below shows a text file called Customer.html that can be compiled with the Query Application Builder tool. As you can see, the file contains standard HTML tags and also contains a form with a submit button that, when tapped with the stylus, gets posted to a Domino server.

.BEGIN_CODE


PalmBuilder



PalmBuilder.com

Customer Tracking Demo

Developed by Bruce Elgort

DominoPower and PalmPower


Enter a Customer Name:




.END_CODE

Notice that when our form gets posted to the Domino server the pqaCustomerQuery agent is actually run. This agent will take the data from the form and then generate a Web clipping that will be sent to the Palm VII for display. Let’s look at the form tag again:

.BEGIN_CODE

.END_CODE

Figure A shows the Query Application Builder tool with the Customer.html file loaded. To build the PQA, select Build PQA from the File menu. When you build the PQA, you can supply a name that will be displayed underneath the icon on the Palm VII and you can also select a custom icon that you may have developed.

.FIGPAIR A The Query Application Builder tool with our sample file Customers.html loaded.

If our PQA consisted of more than one file and/or graphic, all of them would be listed in the Query Application Builder.

Now that the PQA is built, the HotSync program can be used to install it onto the Palm VII. Figure B shows the Customers icon in the upper right-hand corner of the Palm VII display.

.FIG B The Customers PQA icon on the Palm VII.

Figure C shows the HTML form we designed in the code shown earlier in this article. Notice the Go submit button and the lines to the right of it. These lines indicate that tapping this button with the stylus will perform an "over the air" function and will require the user to raise the antenna on the Palm VII in order to complete the transaction.

.FIG C This is the Customers PQA asking for a customer name.

Figure D shows that I have requested the PQA to find all documents in the database that contain the word "Evergreen".

.FIG D Search for all Customer documents that contain the word "Evergreen".

Figure E shows the Web clipping generated by the LotusScript agent on the Domino server. Notice that there is a History button on the top right of Figure E. This button functions like the Address History in a Web browser. It stores past queries. Also notice the title "PalmBuilder" in the upper left corner. The LotusScript agent Web clipping generates both the History and the PalmBuilder elements.

.FIG E The Web clipping generated by the Domino server.

.H1 The Web clipping LotusScript agent
So far I have shown you the PQA itself and how to create one for the Customer Tracking database. Now let’s take a look at the Domino side of the equation and more specifically the agent used to generate the Web clipping.

.BEGIN_SIDEBAR
Here’s the code that actually generates the Web clipping content.

.BEGIN_CODE
Sub Initialize
‘Dimension some Objects
Dim s As New NotesSession
‘doc is the document posted by the PQA
‘cdoc is the actual customer document in the database
Dim doc, cdoc As NotesDocument
Dim db As NotesDatabase
Dim c As NotesDocumentCollection
Dim dateTime As New NotesDateTime(“12/01/80″)
‘Get a handle to the document posted to the Domino server
Set doc = s.DocumentContext
‘Read the REQUEST_CONTENT CGI variable and get the Customer name entered on
the PQA
Customer$ = Mid$(doc.REQUEST_CONTENT(0),Instr(1,doc.REQUEST_CONTENT(0),”=”)
+ 1, Len(doc.REQUEST_CONTENT(0)))
‘Tell the Domino server not to generate a HEAD tag
Print “Content-Type:text/plain”
Print “Content-Type:text/html”
‘Generate our own HEAD tag and generate web clipping Meta tags required by
the PQA
Print “PalmBuilder
Print “
Print “
Print “”
‘Get a handle to the current database
Set db = s.currentdatabase
‘Search the database for the Customer name entered. Results are placed in a
document collection
Set c = db.ftsearch(Customer$, 0)
‘How many did we find?
Print “Found ” & c.count & ” matches for customer ” & Ucase$(Customer$) &



‘Did we find any documents?
If c.count >= 1 Then
‘Loop through each document in the collection
For i = 1 To c.count
‘Get a handle to the document
Set cdoc = c.getnthdocument(i)
‘Generate the company name
Print “” & cdoc.CompanyName(0) & “


Print cdoc.FirstName(0) & ” ” & cdoc.LastName(0) & “


‘If there is a Phone number then let them know
If cdoc.Phone(0) <> “” Then
Print “Phone: ” & cdoc.Phone(0) & “


End If
‘If there is a FAX number then let them know
If cdoc.FAX(0) <> “” Then
Print “FAX: ” & cdoc.FAX(0) & “


End If
‘If there is a Customer Type assigned then let them know
If cdoc.CustomerType(0) <> “” Then
Print “Customer Type: ” & cdoc.CustomerType(0) & “


End If
‘If there is a Customer Status assigned then let them know
If cdoc.Status(0) <> “” Then
Print “Status: ” & cdoc.Status(0) & “


End If
‘If there is a Sales Person assigned then let them know
If cdoc.SalesPerson(0) <> “” Then
Print “Sales Person: ” & cdoc.SalesPerson(0) & “



End If
Next i
Else
‘Oh no – no customer matches!
Print “

No Customers were found for your query


End If
‘Give the user a way to go back and query another customer
Print “Back


End Sub
.END_CODE
.END_SIDEBAR

.H1 Looking at the LotusScript agent code
Now let’s dig into the code a bit and discuss some of the things you should include in your Web clipping scripts.

When the form is posted to the Domino server, there is a CGI variable called REQUEST_CONTENT that contains all of the values of the fields on the form. In our sample there is only one field called "Customer". The following code gets the value of the Customer field and stores it in Customer$.

.BEGIN_CODE
Customer$ = Mid$(doc.REQUEST_CONTENT(0),Instr(1,doc.REQUEST_CONTENT(0),”=”) + 1, Len(doc.REQUEST_CONTENT(0)))
.END_CODE

When you generate a Web clipping, you need to put some information in the HEAD section of the resulting HTML. Since Domino likes to generate its own HEAD data, we need to tell Domino not to generate a HEAD section. These two lines of code prevent Domino from generating the HEAD section:

.BEGIN_CODE
Print “Content-Type:text/plain”
Print “Content-Type:text/html”
.END_CODE

Now that we told Domino not to generate a HEAD section we need to generate our own. Notice the meta tags in the HEAD section — palmcomputingplatform and historylistext. These two tags tell the Palm VII that the data it’s about to receive is intended for it, and that the History should contain the name of the Customer entered.

.BEGIN_CODE
Print “PalmBuilder
Print “
Print “
Print “”
.END_CODE

For the sake of simplicity we’ll use the database search method to find records in the database that contain the customer name we entered. You can refine your search using other Notes classes such as the new R5 NotesViewEntryCollection.

.BEGIN_CODE
Set c = db.ftsearch(Customer$, 0)
.END_CODE

The rest of the LotusScript agent is simple LotusScript document collection processing. For each document in the document collection, we print the customer information from the back-end document.

We also need to provide the user with a way to navigate back to the previous page so that he or she can search for more customers.

.BEGIN_CODE
Print “Back


.END_CODE

Notice the reserved PQA word "file". This tells the Palm VII that the when the Back link is tapped with the stylus to load the Customers.html file in the Customers PQA.

.PAGE
.H1 Extend your applications
Now that I have shown how to write your first PQA, you can now begin to enable your Notes and Domino applications for the wireless revolution. Keep in mind that I didn’t discuss security in this article.

If you build a PQA you’d like to share with everyone, post its link on the PowerBoards (see below) or send a message to news@palmpower.com.

.BEGIN_SIDEBAR
.H1 Product availability and resources
The Palm Application Query Builder is available from Palm.Net at http://www.palm.com/devzone/webclipping/.

More information on the Palm VII’s wireless service can be found at http://www.Palm.net.

If you would like more information about developing PQAs for the Palm VII see http://www.PalmBuilder.com.
.END_SIDEBAR

.BIO Bruce Elgort is an R5 Certified Lotus Certified Professional Application Developer and is a Partner at PalmBuilder.com located in Portland, Oregon (http://www.PalmBuilder.com). Bruce has been working with Notes since release 3.0 and is a frequent contributor to the Notes.net discussion forums (http://www.notes.net). Contact Bruce at BruceElgort@PalmBuilder.com.
.DISCUSS http://powerboards.zatz.com/cgi-bin/webx?13@@.ee6db1b