Have your InfoPath Forms and eat them too
Yeah, a weird title but a rather annoying quirk. InfoPath is an uber-cool tool (and there should be more posts about it!) as it let's you build fairly complex forms and make up for the lack of sophistication that SharePoint lists have for data entry, but still store the data in a Form Library (which then allows you to create views, get subscriptions, etc.). Of course, with any silver bullet/holy grail/insert name here, there are some drawbacks.
Here's one that just irks me to no end. When you design a form you can easily tell it to submit the form to a Form Library by just specifying the location of the library and what fields you want to populate the default view. Easy sleazy. It even puts a Submit button on the toolbar for you so your users just have to click it. However the biggest issue with this is that while you can configure it to close the form, you can't tell it exit out of the application. Trust me, I've been all over Google today and tried everyone's ideas and nothing works.
You can however create your own Submit button (as a button on the form itself) and write the following code attached to the OnClick event of the button:
function CTRL2_5::OnClick(eventObj)
{
XDocument.Submit();
Application.ActiveWindow.Close();
}
This works fine. It submits the form (via whatever way you have the submission setup, SharePoint library, email, etc.) and then closes InfoPath (the application). Great.
Wait a minute. This isn't right. First off, why must I put a Submit button on my form and write an event handler for it in order to close InfoPath. InfoPath gives me a simple way of putting a Submit button on the toolbar (and menu) for this. If I put "Submit" on my form and my users want to print it out, they're going to get a bit ugly button when it prints. That's ugly. There is an event on the submit process, but it's basically an event to make you do all the work the normal XDocument.Submit() does. The problem is that you can't have InfoPath do a Submit to say a SharePoint Form Library from your own OnClick event unless you write all of that code in JavaScript. You need both the Toolbar Submit button to exist in order to call the XDocument.Submit() without having to specify all the nitty gritty details (the ones you can enter if you used the built in Submit dialog) in hard-coded JavaScript (or VB Script but it doesn't make it any better). Blech.
In other words I'm caught between a rock and a hard place if I want to a) use the built-in submit mechanism and b) exit InfoPath completely.
Why is this so difficult. Really? I challenge anyone out there to show me an elegant solution that does this. Sure, the code above works if I click on the forms Submit button (i.e. InfoPath quits) but if the user clicks on the toolbars Submit button (which has to be there, otherwise I have to write a gob of JavaScript in my OnClick) it just closes the form (or whatever option I choose, like leave the form open). I don't see a way to have my cake and eat it too.
Odd that it was designed this way. Why not add the option on the Submit to 1) Close the Form 2) Open a Blank Form 3) Leave the Form Open or hey, what about a new option like 4) Close the Application. Seems everyone wants to do this and you can, but you just have to use your own button and tell your users to ignore the Submit button on the menu or toolbar.