iCommand Example
You need to create a data entry screen for employee data including last name, first name, address, city, postal code, and home phone number. You could perform a database insert in a number of ways; however, a post must be performed and the screen must be reloaded if you are using HTML forms only. If you use the iCommand, you can perform the data entry, have the iCommand execute the insert statement to a database, and never execute a post or get. In this way, the page load is alleviated, and the user does not need to wait while the page blinks. Processing occurs in the background through applet-to-server communication.
You can create the insert command by selecting the SQL data source and Command
mode in the query template. On the Fixed Query
screen, enter the following command:
UPDATE Employee SET Name='[Param.1]', Phone='[Param.2]', Address='[Param.3]', State='[Param.4]',
ZipCode='[Param.5]', Status='[Param.6]', EMail='[Param.7]' WHERE Employee ID='[Param.8]'
On the Web page, you can use scripting to populate the insert command parameters (Param.1 through Param.7). You could use an Update
or Modify
button with a similar query. The example below shows the Insert command initiated by the Enter New Employee Information
button. The iCommand applet looks like any other applet in HTML:
<APPLET NAME="EmployeeInsert" CODEBASE="/Illuminator/Classes" CODE="iCommand" ARCHIVE="illum8.zip"
WIDTH="1" HEIGHT="1" MAYSCRIPT>
<PARAM NAME="QueryTemplate" VALUE="Training/EmployeeUpdateQuery">
</APPLET>
On the HTML page, you could set up the Enter New Employee Information
button to call a script function named doUpdate
:
<input type="button" value="Enter New Employee Information" name="btnUpdate" onClick="doUpdate()">
The doUpdate
function might look like the following:
function doUpdate() {
// get the iCommand applet query object so you can set its parameters before executing
var commandObject = document.EmployeeInsert.getQueryObject();
//Set required query parameters based upon their corresponding form field values.
//txtName, etc., are the names of the form text boxes for data entry
//setParam sets the input parameters for the query template shown above
commandObject.setParam(1,document.F1.txtName.value);
commandObject.setParam(2,document.F1.txtPhone.value);
commandObject.setParam(3,document.F1.txtAddress.value);
commandObject.setParam(4,document.F1.txtState.value);
commandObject.setParam(5,document.F1.txtZip.value);
commandObject.setParam(6,document.F1.txtStatus.value);
commandObject.setParam(7,document.F1.txtEMail.value);
//call the executeCommand method for the iCommand object.
// it returns a true/false (true if successful)
if(document.OrderDetailsUpdate.executeCommand()) {
//refresh Employee Grid applet if successful
document.EmployeeGrid.updateGrid(true);
//clear all user input form fields if successful
document.F1.txtName.value = "";
document.F1.txtPhone.value = "";
document.F1.txtAddress.value = "";
document.F1.txtState.value = "";
document.F1.txtZip.value = "";
document.F1.txtStatus.value = "";
document.F1.txtEMail.value = "";
}
else {
//Put Error handling here
alert("Unable To Execute Command!");
}
}
The insert is performed by the applet using the document.<appletname>.executeCommand
method. Error handling can be performed using Web page scripting based on the results of the executeCommand
method. As shown in the example, the executeCommand
method returns True
or False
based on execution success or failure. You can use the return value to handle the error in any way you choose.