SelectSingleNode

B

BFSmith

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)
 
G

Greg Collins [InfoPath MVP]

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)
 
B

BFSmith

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)
 
B

BFSmith

Here it is:

/*
* 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: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-24T18:16:36"');
//</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_CustName_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.

// Get the DOM for the Seconday Data Source
var dat = XDocument.DataObjects("CustomerInfo").DOM;
var ns =
"xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'
xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\'";
dat.setProperty("SelectionNamespaces", ns);


// Get the value of the selected item in the dropdown list
var sVariable =
getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustName");

// Get the node from the Seconday Data Source using the value from the
dropdown list
var xNode =
dat.selectSingleNode("/dfs:myFields/dfs:dataFields/d:vwCustomerInfo_basic[@Name='" + sVariable + "']");

// If the value is not null (shouldn't be but j.i.c.)
if (xNode == null)
{
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum", "");
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr1", "");
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr2", "");
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr3", "");
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustZIP", "");
}
else
// Set the values in the form DOM using the values from the Seconday Data
Source DOM
{
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum",
xNode.selectSingleNode("@Customer").text);
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr1",
xNode.selectSingleNode("@Address1").text);
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr2",
xNode.selectSingleNode("@Address2").text);
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr3",
xNode.selectSingleNode("@Address3").text);
setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustZIP",
xNode.selectSingleNode("@Zip").text);
}



}


/*
=============================================================================
Node value operation
============================================================================= */

/*------------------------------------------------------------------------------
isInvalidOrEmpty(
------------------------------------------------------------------------------*/
function isInvalidOrEmpty(xmlNode)
{
// If there is no value, ignore it.
if (!xmlNode || !xmlNode.text)
return true;

// The caller can pass additional error types as optional arguments.
var aErrorTypes = new Array;
if (arguments.length > 1)
{
for (var i=1; i<arguments.length; i++)
aErrorTypes.push(arguments);
}
else
{
aErrorTypes.push("SCHEMA_VALIDATION");
}

// If there is a validation error related to this node,
// then the node is invalid.
for (var i=0; i<XDocument.Errors.Count; i++)
{
var oError = XDocument.Errors(i);

if (xmlNode == oError.Node)
{
for (var j in aErrorTypes)
{
if (oError.Type == aErrorTypes[j])
return true;
}
}
}

// Is valid (no error was found).
return false;
}


/*------------------------------------------------------------------------------
getNodeValue()
------------------------------------------------------------------------------*/
function getNodeValue(xpath, defaultValue)
{
var xmlNode = getNode(xpath);

if (isInvalidOrEmpty(xmlNode))
return (arguments.length > 1) ? defaultValue : "";
else
return xmlNode.text;
}

/*------------------------------------------------------------------------------
getNode()
------------------------------------------------------------------------------*/
function getNode(xpath)
{
// Both XML node and absolute XPath are allowed.
if (typeof(xpath) == "string")
return XDocument.DOM.selectSingleNode(xpath);
else
return xpath;
}

/*------------------------------------------------------------------------------
setNodeValue()
------------------------------------------------------------------------------*/
function setNodeValue(xpath, value)
{
var xmlNode = getNode(xpath);

if (!xmlNode)
return;

// Setting the value would mark the document as dirty.
// Let's do that if the value has really changed.
if (xmlNode.text != value)
xmlNode.text = value;
}





BFSmith said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top