iTP Active Transaction Pages (iTP ATP) Programmer's Guide

ATP Web Page and Script Structure
iTP Active Transaction Pages (iTP ATP) Programmer’s Guide522292-002
3-9
Using Pathway TS/MP Servers from JavaScript
Accepting the Request from the Browser
To identify the kind of request received from the browser, the script
(/examples/pathway/homebank/Webpages/address.atp) examines the
atp.request object. Specifically, it tests the REQUEST_METHOD environment
variable, which is a property of the atp.request object. A value of POST indicates
that the user submitted a transaction.
So far this example is like the SQL example.
Performing the Requested Transaction
To send a request to a server class, the script
(/examples/pathway/homebank/Webpages/address.atp) creates an
instance of the atp.dictionary object. This object represents a Data Definition
Language (DDL) dictionary that defines the message layouts meaningful to the server
class. (Alternatively, a script author could use output from the dview tool, which
allows passive use of the DDL dictionary.)
Next the script creates an atp.buffer object to hold the request and later the reply.
The setData method fills the buffer, using data from the request as represented by the
atp.request object. To place values in multiple fields, a script must invoke the
setData method once for each field; for example, a script could use a loop to fill rows
of a table.
To update the database, the script calls the send_to_server function, which
1. Creates an atp.transaction object to protect the database update.
2. Uses the send method of the atp.buffer object to send the buffer to the server
class specified in the function call.
3. Checks the Pathsend error code, stored in the error property of the atp.buffer
object.
4. Commits or rolls back the transaction, using methods of the atp.transaction
object.
The reply to the request is in the reply property of the atp.buffer object. The
reply property is itself a buffer object, named replyBuf in this example. To extract
the fields from the reply, the send_to_server function uses the
atp.dictionary object, which defined the message formats, and the getData
method applied to the atp.buffer object replyBuf.
Upon return from send_to_server, the script checks for a message in the reply
buffer and prints the message if there is one.