<?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: Insert &amp;amp; Remove an optional section</title><link>https://www.infopathdev.com:443/forums/thread/13414.aspx</link><pubDate>Fri, 28 Apr 2006 00:28:03 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:13414</guid><dc:creator>SamDahl</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/13414.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=13414</wfw:commentRss><description>Solution achieved! (quite proud of that as a second year uni student on work placement)&lt;br /&gt;&lt;br /&gt;Effectively what I'm doing is testing whether a variable inside the optional section is there (i'e the section is inserted), I used a hidden text field with default text and a UI.Alert to display it. If the section is not inserted it throws an error and I catch and insert the section.&lt;br /&gt;Since I didn't want a UI.Alert all the time I changed it to storing a variable for no better reason than to see if I can. Surely there's a better way to do that?&lt;br /&gt;&lt;br /&gt;here's my code:&lt;br /&gt;(I really should comment my code)&lt;br /&gt;&lt;br /&gt;function msoxd_my_deviceType::OnAfterChange(eventObj)&lt;br /&gt;{&lt;br /&gt;// Write code here to restore the global state.&lt;br /&gt;&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;	var serverSection;&lt;br /&gt;	var switchSection;&lt;br /&gt;	var switchTest;&lt;br /&gt;	var serverTest;&lt;br /&gt;	var typeValue = XDocument.DOM.selectSingleNode("/my:myFields/my:group4/my:deviceType");&lt;br /&gt;&lt;br /&gt;	if (typeValue.text == "Switch")&lt;br /&gt;	{&lt;br /&gt;		try&lt;br /&gt;		{&lt;br /&gt;			switchSection = XDocument.DOM.selectSingleNode("//*[local-name()='isSwitchesOption']");&lt;br /&gt;			switchTest = switchSection.text;&lt;br /&gt;		}&lt;br /&gt;		catch(exception)&lt;br /&gt;		{&lt;br /&gt;			eventObj.XDocument.View.ExecuteAction("xOptional::insert","group32_54");&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	if (typeValue.text == "Server")&lt;br /&gt;	{&lt;br /&gt;		try&lt;br /&gt;		{&lt;br /&gt;			serverSection = XDocument.DOM.selectSingleNode("//*[local-name()='isServerOption']");&lt;br /&gt;			serverTest = serverSection.text;&lt;br /&gt;		}&lt;br /&gt;		catch(exception)&lt;br /&gt;		{&lt;br /&gt;			eventObj.XDocument.View.ExecuteAction("xOptional::insert","group55_69");&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;}</description></item><item><title>Re: Insert &amp;amp; Remove an optional section</title><link>https://www.infopathdev.com:443/forums/thread/13413.aspx</link><pubDate>Wed, 26 Apr 2006 06:33:03 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:13413</guid><dc:creator>SamDahl</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/13413.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=13413</wfw:commentRss><description>I'm having the same error with fundamentally the same situation.&lt;br /&gt;&lt;br /&gt;I have a DDL called deviceType.&lt;br /&gt;I have multiple optional sections relevant to different devices. &lt;br /&gt;(for this test I'll use 2)&lt;br /&gt;&lt;br /&gt;When the user selects the device type I want the relevant optional section to open.&lt;br /&gt;&lt;br /&gt;I've used the following code:&lt;br /&gt;(note the 4 alert messages to track the flow of operation)&lt;br /&gt;&lt;br /&gt;function msoxd_my_deviceType::OnAfterChange(eventObj)&lt;br /&gt;{&lt;br /&gt;// Write code here to restore the global state.&lt;br /&gt;	try&lt;br /&gt;	{&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;		XDocument.UI.Alert("Function Test");&lt;br /&gt;&lt;br /&gt;		var typeValue = XDocument.DOM.selectSingleNode("/my:myFields/my:group4/my:deviceType");&lt;br /&gt;&lt;br /&gt;		if (typeValue.text == "Switch")&lt;br /&gt;		{&lt;br /&gt;			try&lt;br /&gt;			{&lt;br /&gt;				XDocument.UI.Alert("Switch Try");&lt;br /&gt;				var view = eventObj.XDocument.View;&lt;br /&gt;				view.ExecuteAction("xOptional::insert","group32_54");	&lt;br /&gt;			}&lt;br /&gt;			catch(exception)&lt;br /&gt;			{&lt;br /&gt;				XDocument.UI.Alert("Switch Error");&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		if (typeValue.text == "Server")&lt;br /&gt;		{&lt;br /&gt;			try&lt;br /&gt;			{&lt;br /&gt;				XDocument.UI.Alert("Server Try");&lt;br /&gt;				var view = eventObj.XDocument.View;&lt;br /&gt;				view.ExecuteAction("xOptional::insert","group55_69");	&lt;br /&gt;			}&lt;br /&gt;			catch(exception)&lt;br /&gt;			{&lt;br /&gt;				XDocument.UI.Alert("Server Error");&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;	catch(exception)&lt;br /&gt;	{&lt;br /&gt;		XDocument.UI.Alert("Function Error");&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This works perfectly for the initial selection.&lt;br /&gt;&lt;br /&gt;You select switch in the DDL and the switch section opens. No problem.&lt;br /&gt;Alerts seen:&lt;br /&gt;"Function Test"&lt;br /&gt;"Switch Try"&lt;br /&gt;&lt;br /&gt;If I then select Server in the DDL, I get&lt;br /&gt;"Function Test"&lt;br /&gt;"Server Try"&lt;br /&gt;"Function Test"&lt;br /&gt;"Server Try"&lt;br /&gt;Infopath error: "InfoPath cannot insert the section because of an error"&lt;br /&gt;-&amp;gt;Details: "The attempted fragment operation cannot be completed because there is no valid insertion point for the fragment."&lt;br /&gt;[the Server optional section opens]&lt;br /&gt;&lt;br /&gt;&lt;font color="maroon"&gt;(note the function appears to run twice: succeed once and then fail. The onAfterChange event triggers twice? once when Switch is deselected and again when Server is selected? if this is the case how would I handle this?) &lt;/font id="maroon"&gt;&lt;br /&gt;&lt;br /&gt;Some further scenarios I tested:&lt;br /&gt;&lt;br /&gt;If I then select Switch in the DDL I get:&lt;br /&gt;"Function Test"&lt;br /&gt;"Switch Try"&lt;br /&gt;"Switch Error"&lt;br /&gt;"Function Test"&lt;br /&gt;"Switch Try"&lt;br /&gt;"Switch Error"&lt;br /&gt;(this is acceptable: won't be noticed when alerts are removed)&lt;br /&gt;&lt;br /&gt;If I then delete the Server section and then choose Server in the DDL I get:&lt;br /&gt;"Function Test"&lt;br /&gt;"Server Try"&lt;br /&gt;"Function Test"&lt;br /&gt;"Server Try"&lt;br /&gt;Infopath error: "InfoPath cannot insert the section because of an error"&lt;br /&gt;[the Server optional section opens]&lt;br /&gt;&lt;br /&gt;Any ideas how to stop this error occurring?</description></item><item><title>Insert &amp; Remove an optional section</title><link>https://www.infopathdev.com:443/forums/thread/12515.aspx</link><pubDate>Thu, 28 Jul 2005 21:39:44 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:12515</guid><dc:creator>jeanpaul</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/12515.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=12515</wfw:commentRss><description>I am using the ExecuteAction to insert an optional section, if a specific value is selected in a drop down menu (note the optional section is in a repeated section). First time the drop down value matches it inserts the optional section with out a problem but if I remove the section and then try to reselect the value in the drop down menu it gives me the following error&lt;br /&gt;&lt;br /&gt;"The attempted fragment operation cannot be completed because there is no valid insertion point for the fragment."&lt;br /&gt;&lt;br /&gt;and then it still inserts the section....How can I get rid of this error...&lt;br /&gt;&lt;br /&gt;Code Below&lt;br /&gt;&lt;br /&gt;&amp;lt;InfoPathEventHandler(MatchPath:="/mstns:SHORT_SEARCH/mstns:INSTRUMENT/mstns:INST_NAME", EventType:=InfoPathEventType.OnAfterChange)&amp;gt; _&lt;br /&gt;        Public Sub INST_NAME_OnAfterChange(ByVal e As DataDOMEvent)&lt;br /&gt;&lt;br /&gt; If thisXDocument.DOM.getElementsByTagName("mstns:INST_NAME").Item(0).text = "DEED" Then&lt;br /&gt;                thisXDocument.View.ExecuteAction("xOptional::insert", "DEED_30")&lt;br /&gt;            End If&lt;br /&gt;End Sub</description></item></channel></rss>