OK..got that...I posted "Mapping secondary data to main source" earlier and I
think my problems with that, as well as this issue, are related. First-this
is my first IP form. I don't seem to be able to acquire field and data
correctly. In this code I am trying to populate the CustName (field & main
data) with the secondary data returned from a query. I keep getting NULL
references to the field and the data. Obviously, I'm missing something. Also,
I've spent many hours trying to find a decent example of this. Just using SQL
Server2000 and IP. What a pain for such a trivial problem! Any help will be
appreciated!
Main data source: tblRAHeader (SQL table)
CustomerNum
CustName
Secondary data source: vwCustomerInfo_basic (SQL view)
Cutomer (I'll fix the spelling later)
Name
CODE:
/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/
// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:q="
http://schemas.microsoft.com/office/infopath/2003/ado/queryFields"
xmlns:d="
http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
xmlns:dfs="
http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
xmlns:my="
http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-11T01:52:18" xmlns:xd="
http://schemas.microsoft.com/office/infopath/2003"');
//</namespacesDefinition>
//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
// This function is associated with the following field or group (XPath):
/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum
// Note: Information in this comment is not updated after the function
handler is created.
//=======
function msoxd__tblRAHeader_CustomerNum_attr::OnAfterChange(eventObj)
{
// Write code here to restore the global state.
if (eventObj.IsUndoRedo)
{
// An undo or redo operation has occurred and the DOM is read-only.
return;
}
// A field change has occurred and the DOM is writable. Write code here to
respond to the changes.
// Retrieve the vwCustomerInfo_basic secondary data source
// get the customer info that corresponds to this customer from the
vwCustomerInfo_basic auxiliary node
XDocument.GetDOM("vwCustomerInfo_basic").setProperty("SelectionNamespaces",
'xmlns:q="
http://schemas.microsoft.com/office/infopath/2003/ado/queryFields"
' +
'xmlns:d="
http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" '
+
'xmlns:dfs="
http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
// Retrieve the SQL statement of the data source
var strSQL =
XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command;
XDocument.UI.Alert(strSQL);
// Retrieve the field in the InfoPath form whose value will be used in the
WHERE clause
//var fCustomerNum =
XDocument.DOM.selectSingleNode("/my:myFields/my:CustomerNum");
//XDocument.UI.Alert(fCustomerNum == null);
//XDocument.UI.Alert(fCustomerNum.text);
var strCustomerId = eventObj.NewValue;
XDocument.UI.Alert(eventObj.NewValue);
// Generate the new SQL statement with WHERE clause
strSQL += " where vwCustomerInfo_basic.Cutomer = ' " + eventObj.NewValue +
" '";
XDocument.UI.Alert(strSQL);
// Populate the command with the new SQL statement
XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command = strSQL;
// Run the query
XDocument.DataObjects["vwCustomerInfo_basic"].Query();
// Get the CustomerName node in the XML Document
var objCustomerNode = XDocument.DOM.selectSingleNode("//tblRAHeader");
// Find the customer name in the secondary data source and the main data
source
var objCustomerLookupNode = XDocument.GetDOM("vwCustomerInfo_basic");
// Update the main data source with the queried value;
// Populate XML document with customer information.
objCustomerNode.selectSingleNode('CustName').text =
objCustomerLookupNode.getAttribute("Name") || "";
}
Greg Collins said:
Two problems:
1. "selectSingleNode" (lowercase "s") not "SelectSingleNode".
2. "//:" is invalid... you probably mean "//my:"
--
Greg Collins [InfoPath MVP]
Visit
http://www.InfoPathDev.com
I don't seem to be able to get a valid node using
node = XDocument.DOM.SelectSingleNode("../my:CustName") or
node = XDocument.DOM.SelectSingleNode("//:CustName")
I keep getting "Object doesnt support this property or method"
Using:
function msoxd__tblRAHeader_CustomerNum_attr::OnAfterChange(eventObj)