iTP Active Transaction Pages (iTP ATP) Programmer's Guide
ATP Web Page and Script Structure
iTP Active Transaction Pages (iTP ATP) Programmer’s Guide—522292-002
3-13
Using NonStop TUXEDO Servers from JavaScript
For more information about doTransfer, see Performing the Requested Transaction
on page 3-13.
Accepting the Request from the Browser
To identify the kind of request received from the browser, the script
(/examples/tuxedo/bankapp/transfer.atp) examines the atp.request
object. Specifically, the script 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.
Performing the Requested Transaction
To perform the transaction, the script
(/examples/tuxedo/bankapp/transfer.atp) uses the doTransfer
function, which performs the following processing:
1. Creates a new atp.fml_table object to represent the field table. The parameter
specifies the file that contains the table.
Example 3-6. NonStop TUXEDO Server-Side Functions
<server>
//--- T U X E D O T R A N S F E R T R A N S A C T I O N ---
// --------------- U P D A T E F U N C T I O N -------------
function doTransfer (from_acct, to_acct, amount)
{
var ftbl = new atp.fml_table('bank.flds');
var fbfr = new atp.fml_buffer('fml');
fbfr.setData (from_acct, ftbl.ACCOUNT_ID, 0);
fbfr.setData (to_acct, ftbl.ACCOUNT_ID, 1);
fbfr.setData (amount, ftbl.SAMOUNT);
var tran = new atp.transaction ();
if (!fbfr.tpcall('TRANSFER', tran)) {
tran.rollback();
if (fbfr.error != 0)
return ('tpcall TRANSFER failed: ' + fbfr.error_text);
return (fbfr.reply.getData(ftbl.STATLIN));
}
tran.commit ();
return ('Debit Account Balance: ' + fbfr.reply.getData(ftbl.SBALANCE) +
' ; Credit Account Balance: ' + fbfr.reply.getData(ftbl.SBALANCE, 1)
);
}