Hi,
I am trying to customize my submit operation with JScript code so that only records that have a check mark in the 'submit' field will be sent to the database. Here is what i have come up with:
quote:
function submit_button::OnClick(eventObj)
{
// invoke the OnSubmitRequest event handler
XDocument.Submit();
}
function XDocument::OnSubmitRequest(eventObj)
{
// If the submit operation is successful, set
// eventObj.ReturnStatus = true;
var objDOMNode; // stores a node in the DOM
var objNamedNodeMap; // stores a collection of node attributes
var objADOAdapter; // data adapter used to connect to the database
var objDOMNodeList; // stores a list of DOM nodes
var strSQLInsert; // stores an SQL insert statement
// create a DOM Node List to put all the author nodes into
try
{
objDOMNodeList = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields//d:authors2");
}
catch(ex)
{
XDocument.UI.Alert("Could not create XMLDOMNodeList object.\r\n"
+ ex.number + " - " + ex.description);
// Return with eventObj.ReturnStatus == false (the default value)
return;
}
// get the ADO data adapter for the database connection
objADOAdapter = XDocument.QueryAdapter;
// loop through all the records to find the ones that have the resubmit field checked
while( objDOMNode = objDOMNodeList.nextNode() )
{
// get the attribute list for the current DOM Node
objNamedNodeMap = objDOMNode.attributes;
// <DEBUGGING>
//XDocument.UI.Alert("objNamedNodeMap.getNamedItem(\"submit\"): " + objNamedNodeMap.getNamedItem("submit").xml);
// </DEBUGGING>
// Filter out the records that are to be submitted to the database
if( objNamedNodeMap.getNamedItem("submit").nodeValue == "True" )
{
// store the attributes of the current node
ln = objNamedNodeMap.getNamedItem("lname").nodeValue;
fn = objNamedNodeMap.getNamedItem("fname").nodeValue;
addr = objNamedNodeMap.getNamedItem("address").nodeValue;
// if the string value is False assign 0 to avoid conversion problems when submitting to the database
contract = ( (objNamedNodeMap.getNamedItem("contract").nodeValue == "False")? 0 : 1 );
// always set to 0 so that when queries are run none of the records will have a check mark in the submit field
// which could lead to new records being submitted by mistake
submit = 0;
// <DEBUGGING>
XDocument.UI.Alert("contract: " + contract);
// </DEBUGGING>
strSQLInsert = "INSERT INTO authors2(lname,fname,address,contract,submit) VALUES(" +
"'"+ln+"'" + "," + "'"+fn+"'" + "," + "'"+addr+"'" + "," + contract + "," + submit + ")";
objADOAdapter.Command = strSQLInsert;
// <DEBUGGING>
XDocument.UI.Alert("SQL command: " + objADOAdapter.Command);
// </DEBUGGING>
try
{
objADOAdapter.Query();
}
catch(ex)
{
XDocument.UI.Alert("Error executing insert query.\r\n"
+ ex.number + " - " + ex.description);
// Return with eventObj.ReturnStatus == false (the default value)
return;
}
}
// set eventObj.ReturnStatus = true
eventObj.ReturnStatus = true;
}
// store the id attribute from the first author node encountered
}
With the above code i don't get any errors but when i check the corresponding database i see that a new record has not been added.
Any idea what the problem might be?