more on secondary data sources...cant find my data...namespace iss

B

BFSmith

I keep having trouble with this...I cant seem to get a nonNull reference to
my secondary data...all is well (presumably) until the next to last line of
code...always returns a null reference...anybody care to debug?
/*
* 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-21T03:22:17" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
XDocument.GetDOM( "vwCustomerInfo_basic" ).setProperty(
"SelectionNamespaces" ,
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
' );
//</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/@CustName
// 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.
// Retrieve the vwCustomerInfo_basic secondary data source

// Retrieve the SQL statement of the data source
// (the DOM of the vwCustomerInfo_basic Data Object)

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM
XDocument.UI.Alert(customerInfoAuxDom == null);
customerInfoAuxDom.setProperty("SelectionNamespaces",
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');

var strSQL =
XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command;
XDocument.UI.Alert(strSQL);

var strCustName = eventObj.NewValue;
XDocument.UI.Alert(eventObj.NewValue);

// Generate the new SQL statement with WHERE clause
strSQL += " where vwCustomerInfo_basic.Name = ' " + strCustName + " '";
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();
XDocument.UI.Alert("Query has been run");

// Find the Customer in the secondary data source and the CustomerNum in
the main data source
var customerAuxNode = customerInfoAuxDom.selectSingleNode(
"/d0:myFields/d0:Customer"); <<<<====== returns TRUE-ie null ref...namespace
issue?

XDocument.UI.Alert(customerAuxNode == null);


var strCustomer = customerAuxNode.text;
XDocument.UI.Alert(strCustomer);

// Update the main data source with the queried value;
// Populate XML document with customer information.


}
 
S

S.Y.M. Wong-A-Ton

Shouldn't this line

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM

be

var customerInfoAuxDom = XDocument.DataObjects["vwCustomerInfo_basic"].DOM

?
Notice the difference in brackets used: "[" vs. the "(". DataObjects is not
a method, but a collection.
---
S.Y.M. Wong-A-Ton


BFSmith said:
I keep having trouble with this...I cant seem to get a nonNull reference to
my secondary data...all is well (presumably) until the next to last line of
code...always returns a null reference...anybody care to debug?
/*
* 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-21T03:22:17" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
XDocument.GetDOM( "vwCustomerInfo_basic" ).setProperty(
"SelectionNamespaces" ,
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
' );
//</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/@CustName
// 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.
// Retrieve the vwCustomerInfo_basic secondary data source

// Retrieve the SQL statement of the data source
// (the DOM of the vwCustomerInfo_basic Data Object)

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM
XDocument.UI.Alert(customerInfoAuxDom == null);
customerInfoAuxDom.setProperty("SelectionNamespaces",
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');

var strSQL =
XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command;
XDocument.UI.Alert(strSQL);

var strCustName = eventObj.NewValue;
XDocument.UI.Alert(eventObj.NewValue);

// Generate the new SQL statement with WHERE clause
strSQL += " where vwCustomerInfo_basic.Name = ' " + strCustName + " '";
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();
XDocument.UI.Alert("Query has been run");

// Find the Customer in the secondary data source and the CustomerNum in
the main data source
var customerAuxNode = customerInfoAuxDom.selectSingleNode(
"/d0:myFields/d0:Customer"); <<<<====== returns TRUE-ie null ref...namespace
issue?

XDocument.UI.Alert(customerAuxNode == null);


var strCustomer = customerAuxNode.text;
XDocument.UI.Alert(strCustomer);

// Update the main data source with the queried value;
// Populate XML document with customer information.


}
 
B

BFSmith

OK..I did that and still get a null reference from
var customerAuxNode = customerInfoAuxDom.selectSingleNode(
"/d0:myFields/d0:Customer");

I'm pretty sure it's a namespace issue...but here is all the code...so what
should it be...thanks...


S.Y.M. Wong-A-Ton said:
Shouldn't this line

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM

be

var customerInfoAuxDom = XDocument.DataObjects["vwCustomerInfo_basic"].DOM

?
Notice the difference in brackets used: "[" vs. the "(". DataObjects is not
a method, but a collection.
---
S.Y.M. Wong-A-Ton


BFSmith said:
I keep having trouble with this...I cant seem to get a nonNull reference to
my secondary data...all is well (presumably) until the next to last line of
code...always returns a null reference...anybody care to debug?
/*
* 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-21T03:22:17" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
XDocument.GetDOM( "vwCustomerInfo_basic" ).setProperty(
"SelectionNamespaces" ,
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
' );
//</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/@CustName
// 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.
// Retrieve the vwCustomerInfo_basic secondary data source

// Retrieve the SQL statement of the data source
// (the DOM of the vwCustomerInfo_basic Data Object)

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM
XDocument.UI.Alert(customerInfoAuxDom == null);
customerInfoAuxDom.setProperty("SelectionNamespaces",
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');

var strSQL =
XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command;
XDocument.UI.Alert(strSQL);

var strCustName = eventObj.NewValue;
XDocument.UI.Alert(eventObj.NewValue);

// Generate the new SQL statement with WHERE clause
strSQL += " where vwCustomerInfo_basic.Name = ' " + strCustName + " '";
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();
XDocument.UI.Alert("Query has been run");

// Find the Customer in the secondary data source and the CustomerNum in
the main data source
var customerAuxNode = customerInfoAuxDom.selectSingleNode(
"/d0:myFields/d0:Customer"); <<<<====== returns TRUE-ie null ref...namespace
issue?

XDocument.UI.Alert(customerAuxNode == null);


var strCustomer = customerAuxNode.text;
XDocument.UI.Alert(strCustomer);

// Update the main data source with the queried value;
// Populate XML document with customer information.


}
 
S

S.Y.M. Wong-A-Ton

I cannot tell you what the correct XPath should be by just looking at code.
Here is what you can do: Open the InfoPath form to fill it out, fill in some
data, and then save the form locally on disk. Open the XML of the saved form
in Notepad and then look at what the XML structure is to be able to derive
the correct XPath containing the correct namespaces. For more information on
how to use XPath go to http://www.w3.org/TR/xpath
---
S.Y.M. Wong-A-Ton


BFSmith said:
OK..I did that and still get a null reference from
var customerAuxNode = customerInfoAuxDom.selectSingleNode(
"/d0:myFields/d0:Customer");

I'm pretty sure it's a namespace issue...but here is all the code...so what
should it be...thanks...


S.Y.M. Wong-A-Ton said:
Shouldn't this line

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM

be

var customerInfoAuxDom = XDocument.DataObjects["vwCustomerInfo_basic"].DOM

?
Notice the difference in brackets used: "[" vs. the "(". DataObjects is not
a method, but a collection.
---
S.Y.M. Wong-A-Ton


BFSmith said:
I keep having trouble with this...I cant seem to get a nonNull reference to
my secondary data...all is well (presumably) until the next to last line of
code...always returns a null reference...anybody care to debug?
/*
* 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-21T03:22:17" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
XDocument.GetDOM( "vwCustomerInfo_basic" ).setProperty(
"SelectionNamespaces" ,
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
' );
//</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/@CustName
// 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.
// Retrieve the vwCustomerInfo_basic secondary data source

// Retrieve the SQL statement of the data source
// (the DOM of the vwCustomerInfo_basic Data Object)

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM
XDocument.UI.Alert(customerInfoAuxDom == null);
customerInfoAuxDom.setProperty("SelectionNamespaces",
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');

var strSQL =
XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command;
XDocument.UI.Alert(strSQL);

var strCustName = eventObj.NewValue;
XDocument.UI.Alert(eventObj.NewValue);

// Generate the new SQL statement with WHERE clause
strSQL += " where vwCustomerInfo_basic.Name = ' " + strCustName + " '";
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();
XDocument.UI.Alert("Query has been run");

// Find the Customer in the secondary data source and the CustomerNum in
the main data source
var customerAuxNode = customerInfoAuxDom.selectSingleNode(
"/d0:myFields/d0:Customer"); <<<<====== returns TRUE-ie null ref...namespace
issue?

XDocument.UI.Alert(customerAuxNode == null);


var strCustomer = customerAuxNode.text;
XDocument.UI.Alert(strCustomer);

// Update the main data source with the queried value;
// Populate XML document with customer information.


}
 
B

BFSmith

OK..that didnt work...but this does!! I found the sample delaing with MS
Access...I modified it to use SQL Server....awful slow though returning from
the DDLB???

/*
* 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 operations
============================================================================= */

/*------------------------------------------------------------------------------
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;
}






S.Y.M. Wong-A-Ton said:
Shouldn't this line

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM

be

var customerInfoAuxDom = XDocument.DataObjects["vwCustomerInfo_basic"].DOM

?
Notice the difference in brackets used: "[" vs. the "(". DataObjects is not
a method, but a collection.
---
S.Y.M. Wong-A-Ton


BFSmith said:
I keep having trouble with this...I cant seem to get a nonNull reference to
my secondary data...all is well (presumably) until the next to last line of
code...always returns a null reference...anybody care to debug?
/*
* 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-21T03:22:17" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
XDocument.GetDOM( "vwCustomerInfo_basic" ).setProperty(
"SelectionNamespaces" ,
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
' );
//</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/@CustName
// 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.
// Retrieve the vwCustomerInfo_basic secondary data source

// Retrieve the SQL statement of the data source
// (the DOM of the vwCustomerInfo_basic Data Object)

var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM
XDocument.UI.Alert(customerInfoAuxDom == null);
customerInfoAuxDom.setProperty("SelectionNamespaces",
'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');

var strSQL =
XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command;
XDocument.UI.Alert(strSQL);

var strCustName = eventObj.NewValue;
XDocument.UI.Alert(eventObj.NewValue);

// Generate the new SQL statement with WHERE clause
strSQL += " where vwCustomerInfo_basic.Name = ' " + strCustName + " '";
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();
XDocument.UI.Alert("Query has been run");

// Find the Customer in the secondary data source and the CustomerNum in
the main data source
var customerAuxNode = customerInfoAuxDom.selectSingleNode(
"/d0:myFields/d0:Customer"); <<<<====== returns TRUE-ie null ref...namespace
issue?

XDocument.UI.Alert(customerAuxNode == null);


var strCustomer = customerAuxNode.text;
XDocument.UI.Alert(strCustomer);

// Update the main data source with the queried value;
// Populate XML document with customer information.


}
 

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