Lately, we've had a lot of interest in e-mailing a custom view with InfoPath forms that are submitted via e-mail. There are a few simple tricks that will allow you to do this.
Before we start, note that, in the InfoPath rich client, you have the option to "Send to Mail Recipient" from the file menu in the Editor. In this case, you're stuck sending the currently active view of the form. The user filling the form would have to manually click or change data in order to fire an event to switch to a custom view. While this is feasible, we can do better with a pre-defined e-mail submit data connection.
To define an e-mail submit data connection in the InfoPath Designer:
Click "Tools" >> "Data Connections…"
Select "Create a connection to" >> "Submit data" and click "Next >"
Select "As an e-mail message" and click "Next >"
Enter an e-mail address in the "To" header field, or bind it to a field in your form template.
Fill out any other e-mail header information and finish the wizard.
Click "OK" / "Finish" / "Close" to get out of the wizard and finalize your e-mail submit data connection.
Now that we've defined the e-mail submit data connection for our form template, we can move on to the custom view portion…
The easiest option is to send a blank view. To accomplish this, you'll simply want to switch views before you submit. This is easily accomplished using a rule on button click. Here are the steps, in the InfoPath Designer, to configure the "Main Submit" toolbar button to send the blank view:
Create a blank view
On the "View" menu, click "Manage Views…"
In the Views TaskPane, click "Add a new view…"
Type a name for the view and click "OK".
Configure main submit to submit the blank view with the e-mail
Click "Tools" >> "Submit Options…"
Check the "Allow users to submit this form" checkbox.
Select the "Perform custom action using Rules" radio button.
Click the "Rules..." button.
Click "Add..." in the "Rules for Submitting Forms" dialog.
Click "Add Action..." in the "Rule" dialog.
Select "Switch Views" and select the blank view in the "View" drop-down list box.
Click "OK" to close all the dialogs.
Now, when the user clicks "Submit", the view will first be switched to the blank view, and then the form will be submitted to the mail recipients. InfoPath sends the active view contents in the body of the e-mail message, so the blank view will be sent in the message body!
But now the next obvious question is, "Wait a second, I thought we were sending custom views, not just blank ones!" Good call. InfoPath Forms Services treats the "switched-to" view a bit differently than the InfoPath rich client. In browser-enabled form templates filled out in the browser, you can add controls, text, pictures, etc. to the blank view to which we switched before submitting, and the message body will display the data in the custom view, along with the Introduction specified in the e-mail submit data connection wizard. In the InfoPath rich client, you'll still only see the blank view due to view-switching concurrency limitations. So we need an alternate solution…
Basically, instead of e-mailing a custom view, we'll e-mail custom view content. We'll have two sections in one view: one to hold the controls where the user can fill out the form, and one where the custom "view" contents will be stored. Then, at submit time, we'll run a rule to first hide the editing section and show the custom e-mail body section, and then submit via our pre-defined e-mail submit data connection. This works identically in the browser and the InfoPath rich client Editor. Here are the high-level steps:
Insert two "Section" controls into the form view. Name one "EditSection" and the other "EmailSection".
Fill the sections with the relevant controls, formatting, etc. Create your "custom view" inside the "EmailSection" and create the normal form-filling "view" in the "EditSection".
Create a "True/False (boolean)" data source node. Name it "ShowCustomEmailSection", and set its default value to "FALSE".
Add conditional formatting to hide and show the "EmailSection" and "EditSection" sections.
Set the "EditSection" conditional formatting to "hide this control" when "ShowCustomEmailSection" is TRUE.
Set the "EmailSection" conditional formatting to "hide this control" when "ShowCustomEmailSection" is FALSE.
Configure your submit button as above with the blank view case, but, instead of adding a rule action to switch views before submitting, add a rule action to set the value of the "ShowCustomEmailSection" field to the "true()" function. This will conditionally hide the "EditSection" and show the "EmailSection". All that will show up in the message body is an HTML rendering of the contents of the "EmailSection".
And that's it! Note that you may have to set the "Postback Settings" for the relevant controls to "Always" for browser-enabled form templates to get the conditional formatting to work as expected.
Software Design Engineer in Test