<?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: Automatic Submit and Close</title><link>https://www.infopathdev.com:443/forums/thread/88408.aspx</link><pubDate>Wed, 27 Mar 2013 09:03:55 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:88408</guid><dc:creator>HHearle</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/88408.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=88408</wfw:commentRss><description>&lt;p&gt;Or you could use SendKeys... you seem quite proficient with code judging from the above.&amp;nbsp;Try&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;var WshShell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;WshShell.SendKeys(&amp;quot;%fx&amp;quot;)&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Again, a user would have to click something to do it but it would probably be better since you could incorporate it into an existing&amp;nbsp;button in the form as the rules always run before the code.&amp;nbsp; Trouble is, when I tried to do this I had error message &amp;quot;Automation Server cannot create object&amp;quot;, but due to intranet policies at work I can&amp;#39;t upgrade the script editor to fix this problem.&amp;nbsp; In theory it should work and would probably suit your needs better.&lt;/p&gt;</description></item><item><title>Re: Automatic Submit and Close</title><link>https://www.infopathdev.com:443/forums/thread/88378.aspx</link><pubDate>Tue, 26 Mar 2013 15:28:50 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:88378</guid><dc:creator>bblanke</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/88378.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=88378</wfw:commentRss><description>I ended up going with just a button the use must click to submit and close the form. I was hoping to get it so the submitting user would not need to do anything.</description></item><item><title>Re: Automatic Submit and Close</title><link>https://www.infopathdev.com:443/forums/thread/88376.aspx</link><pubDate>Tue, 26 Mar 2013 15:04:50 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:88376</guid><dc:creator>HHearle</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/88376.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=88376</wfw:commentRss><description>&lt;p&gt;Why not just use a standard button?&amp;nbsp; You can create the two rules, one to submit, and one to close the form.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Or if you still want that insanely long code above, use that as the code and then have the rule to close it.&lt;/p&gt;</description></item><item><title>Automatic Submit and Close</title><link>https://www.infopathdev.com:443/forums/thread/87888.aspx</link><pubDate>Mon, 11 Mar 2013 13:58:40 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:87888</guid><dc:creator>bblanke</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/87888.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=87888</wfw:commentRss><description>&lt;p&gt;I have a form that takes in some input parameters, passed from an prior process. These are the only fields that need to be populated. I would like once the input parameters are set in the form to Submit and Close the form with no user input.&lt;/p&gt;

&lt;p&gt;I found a way to get around the inability to have an execute command initiated from Form Loading event, by having the form loading event edit a field and based on the change of that field it call the submit process.&lt;/p&gt;

&lt;p&gt;The form submits fine, but errors when I try to close the form.&lt;/p&gt;



&lt;pre class="western"&gt;using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using mshtml;

namespace JSR_Issue_Tracking
{
    public partial class FormCode
    {
        public void InternalStartup()
        {
            EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
            ((ButtonEvent)EventManager.ControlEvents[&amp;quot;Submit&amp;quot;]).Clicked += new ClickedEventHandler(Submit_Clicked);
            EventManager.XmlEvents[&amp;quot;/my:myFields/my:xmlFilename&amp;quot;].Changed += new XmlChangedEventHandler(xmlFilename_Changed);
        }

        public void FormEvents_Loading(object sender, LoadingEventArgs e)
        {
            XPathNavigator xn = this.MainDataSource.CreateNavigator();

            if (String.IsNullOrEmpty(xn.SelectSingleNode(&amp;quot;/my:myFields/my:jsrID&amp;quot;, NamespaceManager).Value))
            {
                try
                {
                    string _jsrID = e.InputParameters[&amp;quot;jsrid&amp;quot;];
                    string _jobName = e.InputParameters[&amp;quot;jobname&amp;quot;];
                    string _titleCode = e.InputParameters[&amp;quot;titlecode&amp;quot;];
                    string _psr = e.InputParameters[&amp;quot;psr&amp;quot;];

                    xn.SelectSingleNode(&amp;quot;/my:myFields/my:jsrID&amp;quot;, NamespaceManager).SetValue(_jsrID);

                    xn.SelectSingleNode(&amp;quot;/my:myFields/my:jobName&amp;quot;, NamespaceManager).SetValue(_jobName);

                    xn.SelectSingleNode(&amp;quot;/my:myFields/my:titleCode&amp;quot;, NamespaceManager).SetValue(_titleCode);

                    xn.SelectSingleNode(&amp;quot;/my:myFields/my:PSR&amp;quot;, NamespaceManager).SetValue(_psr);

                    Set_XML_Filename();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(&amp;quot;An error occured while trying to import data into the form.\nPlease manually fill in the top row and click submit.&amp;quot;,
                        &amp;quot;Error on Import&amp;quot;, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
            }
        }

        private void Set_XML_Filename()
        {
            XPathNavigator xn = this.MainDataSource.CreateNavigator();
            string xname = xn.SelectSingleNode(&amp;quot;/my:myFields/my:xmlFilename&amp;quot;, NamespaceManager).Value;

            if (String.IsNullOrEmpty(xname))
            {
                xname = Convert.ToString(long.Parse(System.DateTime.Now.ToString(&amp;quot;yyyyMMddHHmmssfff&amp;quot;)), 16).ToUpper();
                xn.SelectSingleNode(&amp;quot;/my:myFields/my:xmlFilename&amp;quot;, NamespaceManager).SetValue(xname);
            }
        }

        public void Submit_Clicked(object sender, ClickedEventArgs e)
        {
            Submit_Form();
        }

        private void Submit_Form()
        {
            FileSubmitConnection submit = (FileSubmitConnection)(DataConnections[&amp;quot;SharePoint Library Submit&amp;quot;]);
            try
            {
                submit.Execute();

                MessageBox.Show(&amp;quot;Form Submitted.&amp;quot;, &amp;quot;Success&amp;quot;, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                Application.ActiveWindow.Close(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        public void xmlFilename_Changed(object sender, XmlEventArgs e)
        {
            Submit_Form();
        }
    }
}
&lt;/pre&gt;</description></item></channel></rss>