<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: Default Fields</title><link>https://www.infopathdev.com:443/forums/thread/14346.aspx</link><pubDate>Tue, 28 Feb 2006 14:56:40 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:14346</guid><dc:creator>brandt</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/14346.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=14346</wfw:commentRss><description>I tried submnitting via a rule  on a button and that exhibited the same behavoir...here is my code...could you show me how "to writing an OnSubmit handler to preserve and copy back the data"...you will see the fileds I populate via code below...thnx.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * This file contains functions for data validation and form-level events.&lt;br /&gt; * Because the functions are referenced in the form definition (.xsf) file, &lt;br /&gt; * it is recommended that you do not modify the name of the function,&lt;br /&gt; * or the name and number of arguments.&lt;br /&gt; *&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// The following line is created by Microsoft Office InfoPath to define the prefixes&lt;br /&gt;// for all the known namespaces in the main XML data file.&lt;br /&gt;// Any modification to the form files made outside of InfoPath&lt;br /&gt;// will not be automatically updated.&lt;br /&gt;//&amp;lt;namespacesDefinition&amp;gt;&lt;br /&gt;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"');&lt;br /&gt;//&amp;lt;/namespacesDefinition&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//=======&lt;br /&gt;// The following function handler is created by Microsoft Office InfoPath.&lt;br /&gt;// Do not modify the name of the function, or the name and number of arguments.&lt;br /&gt;// This function is associated with the following field or group (XPath): /dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum&lt;br /&gt;// Note: Information in this comment is not updated after the function handler is created.&lt;br /&gt;//=======&lt;br /&gt;function msoxd__tblRAHeader_CustName_attr::OnAfterChange(eventObj)&lt;br /&gt;{&lt;br /&gt;// Write code here to restore the global state.&lt;br /&gt;&lt;br /&gt;	if (eventObj.IsUndoRedo)&lt;br /&gt;		{&lt;br /&gt;			// An undo or redo operation has occurred and the DOM is read-only.&lt;br /&gt;			return;&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;// A field change has occurred and the DOM is writable. Write code here to respond to the changes.&lt;br /&gt;&lt;br /&gt;	// Get the DOM for the Seconday Data Source&lt;br /&gt;	var dat = XDocument.DataObjects("CustomerInfo").DOM;&lt;br /&gt;	var ns = "xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\'";&lt;br /&gt;	dat.setProperty("SelectionNamespaces", ns);&lt;br /&gt;		&lt;br /&gt;  &lt;br /&gt;	// Get the value of the selected item in the dropdown list&lt;br /&gt;	var sVariable = getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustName");&lt;br /&gt;		&lt;br /&gt;	// Get the node from the Seconday Data Source using the value from the dropdown list&lt;br /&gt;	var xNode = dat.selectSingleNode("/dfs:myFields/dfs:dataFields/d:vwCustomerInfo_basic[@Name='" + sVariable + "']");&lt;br /&gt;				&lt;br /&gt;	// If the value is not null (shouldn't be but j.i.c.)&lt;br /&gt;	if (xNode == null)&lt;br /&gt;	{&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum", "");&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr1", "");&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr2", "");&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr3", "");&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustZIP", "");&lt;br /&gt;	}&lt;br /&gt;	else&lt;br /&gt;	// Set the values in the form DOM using the values from the Seconday Data Source DOM&lt;br /&gt;	{&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum", xNode.selectSingleNode("@Customer").text);&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr1", xNode.selectSingleNode("@Address1").text);&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr2", xNode.selectSingleNode("@Address2").text);&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr3", xNode.selectSingleNode("@Address3").text);&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustZIP", xNode.selectSingleNode("@Zip").text);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* =============================================================================&lt;br /&gt;	Node value operations&lt;br /&gt;============================================================================= */&lt;br /&gt;&lt;br /&gt;/*------------------------------------------------------------------------------&lt;br /&gt;	isInvalidOrEmpty()&lt;br /&gt;------------------------------------------------------------------------------*/&lt;br /&gt;function isInvalidOrEmpty(xmlNode)&lt;br /&gt;{&lt;br /&gt;	// If there is no value, ignore it.&lt;br /&gt;	if (!xmlNode || !xmlNode.text)&lt;br /&gt;		return true;&lt;br /&gt;&lt;br /&gt;	// The caller can pass additional error types as optional arguments.&lt;br /&gt;	var aErrorTypes = new Array;&lt;br /&gt;	if (arguments.length &amp;gt; 1)&lt;br /&gt;	{&lt;br /&gt;		for (var i=1; i&amp;lt;arguments.length; i++)&lt;br /&gt;			aErrorTypes.push(arguments&lt;i&gt;);&lt;br /&gt;	}&lt;br /&gt;	else&lt;br /&gt;	{&lt;br /&gt;		aErrorTypes.push("SCHEMA_VALIDATION");&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	// If there is a validation error related to this node,&lt;br /&gt;	// then the node is invalid.&lt;br /&gt;	for (var i=0; i&amp;lt;XDocument.Errors.Count; i++)&lt;br /&gt;	{&lt;br /&gt;		var oError = XDocument.Errors(i);&lt;br /&gt;&lt;br /&gt;		if (xmlNode == oError.Node)&lt;br /&gt;		{&lt;br /&gt;			for (var j in aErrorTypes)&lt;br /&gt;			{&lt;br /&gt;				if (oError.Type == aErrorTypes[j])&lt;br /&gt;					return true;&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	// Is valid (no error was found).&lt;br /&gt;	return false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*------------------------------------------------------------------------------&lt;br /&gt;	getNodeValue()&lt;br /&gt;------------------------------------------------------------------------------*/&lt;br /&gt;function getNodeValue(xpath, defaultValue)&lt;br /&gt;{&lt;br /&gt;	var xmlNode = getNode(xpath);&lt;br /&gt;&lt;br /&gt;	if (isInvalidOrEmpty(xmlNode))&lt;br /&gt;		return (arguments.length &amp;gt; 1) ? defaultValue : "";&lt;br /&gt;	else&lt;br /&gt;		return xmlNode.text;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*------------------------------------------------------------------------------&lt;br /&gt;	getNode()&lt;br /&gt;------------------------------------------------------------------------------*/&lt;br /&gt;function getNode(xpath)&lt;br /&gt;{&lt;br /&gt;	// Both XML node and absolute XPath are allowed.&lt;br /&gt;	if (typeof(xpath) == "string")&lt;br /&gt;		return XDocument.DOM.selectSingleNode(xpath);&lt;br /&gt;	else&lt;br /&gt;		return xpath;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*------------------------------------------------------------------------------&lt;br /&gt;	setNodeValue()&lt;br /&gt;------------------------------------------------------------------------------*/&lt;br /&gt;function setNodeValue(xpath, value)&lt;br /&gt;{&lt;br /&gt;	var xmlNode = getNode(xpath);&lt;br /&gt;&lt;br /&gt;	if (!xmlNode)&lt;br /&gt;		return;&lt;br /&gt;&lt;br /&gt;	// Setting the value would mark the document as dirty.&lt;br /&gt;	// Let's do that if the value has really changed.&lt;br /&gt;	if (xmlNode.text != value)&lt;br /&gt;		xmlNode.text = value;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//=======&lt;br /&gt;// The following function handler is created by Microsoft Office InfoPath.&lt;br /&gt;// Do not modify the name of the function, or the name and number of arguments.&lt;br /&gt;// This function is associated with the following field or group (XPath): /dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToName&lt;br /&gt;// Note: Information in this comment is not updated after the function handler is created.&lt;br /&gt;//=======&lt;br /&gt;function msoxd__tblRAHeader_ShipToName_attr::OnAfterChange(eventObj)&lt;br /&gt;{&lt;br /&gt;// Write code here to restore the global state.&lt;br /&gt;&lt;br /&gt;	if (eventObj.IsUndoRedo)&lt;br /&gt;		{&lt;br /&gt;			// An undo or redo operation has occurred and the DOM is read-only.&lt;br /&gt;			return;&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;// A field change has occurred and the DOM is writable. Write code here to respond to the changes.&lt;br /&gt;	// Get the DOM for the Seconday Data Source&lt;br /&gt;	var dat = XDocument.DataObjects("ShipToInfo").DOM;&lt;br /&gt;	var ns = "xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\'";&lt;br /&gt;	dat.setProperty("SelectionNamespaces", ns);&lt;br /&gt;		&lt;br /&gt;  &lt;br /&gt;	// Get the value of the selected item in the dropdown list&lt;br /&gt;	var sVariable = getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToName");&lt;br /&gt;		&lt;br /&gt;	// Get the node from the Seconday Data Source using the value from the dropdown list&lt;br /&gt;	var xNode = dat.selectSingleNode("/dfs:myFields/dfs:dataFields/d:vwShipToInfo_RA[@Name='" + sVariable + "']");&lt;br /&gt;				&lt;br /&gt;	// If the value is not null (shouldn't be but j.i.c.)&lt;br /&gt;	if (xNode == null)&lt;br /&gt;	{&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToNum", "");&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr1", "");&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr2", "");&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr3", "");&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToZIP", "");&lt;br /&gt;	}&lt;br /&gt;	else&lt;br /&gt;	// Set the values in the form DOM using the values from the Seconday Data Source DOM&lt;br /&gt;	{&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToNum", xNode.selectSingleNode("@ShipTo").text);&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr1", xNode.selectSingleNode("@Address1").text);&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr2", xNode.selectSingleNode("@Address2").text);&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr3", xNode.selectSingleNode("@Address3").text);&lt;br /&gt;		setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToZIP", xNode.selectSingleNode("@Zip").text);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//=======&lt;br /&gt;// The following function handler is created by Microsoft Office InfoPath.&lt;br /&gt;// Do not modify the name of the function, or the name and number of arguments.&lt;br /&gt;//=======&lt;br /&gt;function XDocument::OnSubmitRequest(eventObj)&lt;br /&gt;{&lt;br /&gt;	// If the submit operation is successful, set&lt;br /&gt;	// eventObj.ReturnStatus = true;&lt;br /&gt;	// Write your code here&lt;br /&gt;}&lt;br /&gt;</description></item><item><title>Re: Default Fields</title><link>https://www.infopathdev.com:443/forums/thread/14345.aspx</link><pubDate>Tue, 28 Feb 2006 06:51:26 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:14345</guid><dc:creator>Patrick Halstead</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/14345.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=14345</wfw:commentRss><description>How about just using a custom submit handler? Create a button and have it submit via a rule. Then it won't pass through the default submit handler. That might do the trick. If not, consider writing an OnSubmit handler to preserve and copy back the data.</description></item><item><title>Default Fields</title><link>https://www.infopathdev.com:443/forums/thread/12794.aspx</link><pubDate>Mon, 27 Feb 2006 19:46:06 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:12794</guid><dc:creator>brandt</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/12794.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=12794</wfw:commentRss><description>I have noticed two different behavoirs with the form after you press submit:&lt;br /&gt;1) If all data is enterd manually-then the data remains on the form after a Submit&lt;br /&gt;2) Any fields that have been programmatically set default to a blank field afte pressing Submit.&lt;br /&gt;&lt;br /&gt;???How to make the fields retain their data after Submit when the data is populated from a secondary data source???&lt;br /&gt;</description></item></channel></rss>