E-Mailing a Custom View
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…"
Click "Add…"
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.
Forrest Dillaway
Software Design Engineer in Test
Comments
Anonymous
March 03, 2009
Hi Scott,I am having an issue, where no matter what view I change to, the view is showing up blank in the email message only. Basically I created a view that is exactly the same as editable view that a user fills out.I can see infopath changing views just fine, but the email is still white. What gives?Thanks,BirklandAnonymous
March 04, 2009
Hi Birkland,I am assuming you are doing this on a button...do you have a Rule on the button that does both items: switch views and sends the mail? If so, then what is occurring is the view switch has not completed before the mail is sent.Do me a favor to test and confirm:Place a button on the view you want to mail that just has the Rule to send the mail via the data connectionFrom your default view, either manually switch to the e-mail view or use a button with a Rule that only does the view switch Does this now work?ScottAnonymous
April 22, 2009
Scott i have the same problem, i have a button with 2 rules one rule change the view, the other view send the mail, the mail goes blank. I tried to change the view and send the mail in 2 differents actions in the same rule with the same result. If I put the button of sending the mail on the view i want to send it works right. This is it sends me the mail with the current view but i need the button form another view. What can i do?Thanks!Anonymous
April 22, 2009
Hi javierapuy,There really is no other option - what we are running into here is simply a timing issue. The action to send the mail occurs immediately after the action to switch the view - whether or not the view is ready. This simply occurs too fast and the view is not completely drawn.ScottAnonymous
April 22, 2009
There is anything i can do to put a "pause" or something like that???ThanksAnonymous
April 22, 2009
Hi javierapuy,Unfortunately I don't know of any way to do this other than using a button on the view you want to mail.ScottAnonymous
April 22, 2009
Scott i found an alternate solution that is good for me.I use sections instead of view and it works. I have luck that i don't need the views. Do you know if this is a known issue?Anonymous
April 22, 2009
Hi javierapuy,Glad you could use just one view. Is this known? Yes - but its not a bug - simply the way InfoPath works.ScottAnonymous
August 26, 2009
I'm using this solution right now and it works wonderfully, until that email gets to my boss and coworkers on their blackberries. All of the fields of data (whether they are expression boxes or text fields) show up as blank, then they have a bunch of image files attached.I'm afraid my only remaining option will be to send a plain text email, is there a way to have Infopath do that, besides scripting, I can do the scripting route if I have to, but as a scripter, I'm inherently lazy...Searching the web for blackberry and infopath is a very involved process, so I'm starting to ask at places where people might already know.Thanks in advance!Anonymous
August 23, 2011
The comment has been removedAnonymous
August 23, 2011
Hi Ponmuthu,Take a look at this blog post - this is what you will need to accomplish your goal:blogs.msdn.com/.../569338.aspxScottAnonymous
March 19, 2014
Hello Scott,I have Infopath the submit via email but all of a sudden the emails are showing blank on the recipients end. By have to form switch to read only view before it submits via email cause this issue?Anonymous
March 19, 2014
Sorry for Typo let me try to explain again.I have Infopath form that submits via email, but all of a sudden the emails are showing blank on the recipients end. By having the form switch to read only view before it submits via email cause this issue?Anonymous
March 20, 2014
I figured it out. I removed the ReadOnly rule on the submit and it's working again. For some reason, I was thinking that the user would be able to edit the form when they received the email which was the reason why I created the Read Only.Anonymous
July 07, 2014
Sounds great, but unable to implement the solution. Some detail in the instructions would be nice. Such as :a.Set the "EditSection" conditional formatting to "hide this control" when "ShowCustomEmailSection" is TRUE.How do you do that?Anonymous
November 13, 2014
I have an email form with 2 views one for the submitter and the second for the approver. I want the first section to be read only once submitted and the 2nd section to be editable upon opening the submitted request. Please assist me on how to complist this.Anonymous
June 03, 2015
I have this working but my IP form is way to wide in the body of the email. I have several sections - all of their settings are the same - but three of the four are stretching out way to far... any ideas how to limit this?Anonymous
July 16, 2015
I have an InfoPath form designed and am using it for several years now. It is a IP template published on SharePoint 2010. Usually one particular plain text field has only 20-30 lines of instructions entered. Recently a user entered well over 100 lines and close to 5000 characters of instructions. No problem. Form can be submitted and opened with all the info. All was well, until I tried to e-mail the form as usual using the SP/IP mail function. It cut off the last part of the instructions. Tried various solutions to no avail. Even went as far as creating a new form with only one text field. Same issue. Everything past around 5000 characters got chopped off when e-mailing. Any suggestions or thoughts?