Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

E-Mailing a Custom View

E-Mailing a Custom View

  • Comments 15

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:

  1. Click "Tools" >> "Data Connections…"

  2. Click "Add…"

  3. Select "Create a connection to" >> "Submit data" and click "Next >"

  4. Select "As an e-mail message" and click "Next >"

  5. Enter an e-mail address in the "To" header field, or bind it to a field in your form template.

  6. Fill out any other e-mail header information and finish the wizard.

  7. 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:

  1. Create a blank view

    1. On the "View" menu, click "Manage Views…"

    2. In the Views TaskPane, click "Add a new view…"

    3. Type a name for the view and click "OK".

  2. Configure main submit to submit the blank view with the e-mail

    1. Click "Tools" >> "Submit Options…"

    2. Check the "Allow users to submit this form" checkbox.

    3. Select the "Perform custom action using Rules" radio button.

    4. Click the "Rules..." button.

    5. Click "Add..." in the "Rules for Submitting Forms" dialog.

    6. Click "Add Action..." in the "Rule" dialog.

    7. Select "Switch Views" and select the blank view in the "View" drop-down list box.

    8. 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:

  1. Insert two "Section" controls into the form view.  Name one "EditSection" and the other "EmailSection".

  2. 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".

  3. Create a "True/False (boolean)" data source node.  Name it "ShowCustomEmailSection", and set its default value to "FALSE".

  4. Add conditional formatting to hide and show the "EmailSection" and "EditSection" sections.

    1. Set the "EditSection" conditional formatting to "hide this control" when "ShowCustomEmailSection" is TRUE.

    2. Set the "EmailSection" conditional formatting to "hide this control" when "ShowCustomEmailSection" is FALSE.

  5. 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

Leave a Comment
  • Please add 1 and 7 and type the answer here:
  • Post
  • 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,

    Birkland

  • 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 connection

    - From 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?

    Scott

  • 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!

  • 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.

    Scott

  • There is anything i can do to put a "pause" or something like that???

    Thanks

  • 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.

    Scott

  • 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?

  • Hi javierapuy,

    Glad you could use just one view. Is this known? Yes - but its not a bug - simply the way InfoPath works.

    Scott

  • 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!

  • Hi,

    I am using MS Infopath2007. I am just trying to send a report to list of email IDs which are captured in the same report using repeatable table with textbox. when I configuring the submit button as to send email, I inserted the "field name" of the text box (which is in the repeateable table)to send the email to all users available in that repeatable table. But in actual, it is sending email only to the first email ID in that table and it is not picking the remaining email IDs. Hope you understand the issue.... can you help me to resolve it?

    Thanks,

    Ponmuthu

  • Hi Ponmuthu,

    Take a look at this blog post - this is what you will need to accomplish your goal:

    blogs.msdn.com/.../569338.aspx

    Scott

  • 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?

  • 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?

  • 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.

  • 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?

Page 1 of 1 (15 items)