Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

Email Submit "To" line (loops in formulas)

Email Submit "To" line (loops in formulas)

Rate This
  • Comments 62
Everyone likes InfoPath's email data connection because it lets you collect forms using email only, no other infrastructure required (no need for Windows SharePoint Services, SQL Server, or even a file share). We've built even more Outlook integration in InfoPath 2007 Beta, but since most of you don't have that yet, let me share a tip that will work in both InfoPath 2003 and 2007.
 
The basics: Single dynamic email address
As your probably know, the To and CC line of the email data connection can come from a textbox in the form by using a formula. To do that, just use the Fx button next to the To line in the data connection wizard:
 
 
The trick: Multiple email addresses from repeating controls
Some forms have a list of names they want to send to, but the simple formula above won't work for that.
 
For example, consider a repeating table that looks like this:
 
 
With this data source (note that "person" is repeating):
 
 
So you want to produce this semicolon-separated list of e-mails:
 
 
 
A good instinct is to use the "concat" function, but unfortunately that only works on the first element in a repeating structure.
 
So then comes the team insight: Our "eval" function returns a list of nodes which actually share an anonymous parent. That means you can use one eval functions to create a list of the email addresses, then wrap it in another eval function that gets the parent of that list.
 
Voila, here's the formula to solve the problem:
eval(eval(person, "concat(my:email, ';')"), "..")
 
(Note that "person" can be inserted from the data source, but "my:email" needs to be typed by hand or you'll get an error.)
 
For the curious: Here's how it's done
Let's break down that XPath formula from the inside out:
 
  • "concat(my:email, ';')" - Adds a semicolon to each email address.
  • eval(person, "concat(my:email, ';')") - Loops through each person to create a list of email addresses
  • eval(eval(person, "concat(my:email, ';')"), "..") - Gets the anonymous parent of the email addresses, and converts them to a string.
 
So the end result returns the contents of that anonymous parent, which is a series of semicolon-delimited email addresses. Phew!
 
In summary
We are using two tricks here:
  • The fields returned by eval() all have the same anonymous parent (feature of InfoPath's function)
  • The string value of a parent is the concatenation of all its children (W3C spec’ed)
 
- David Airapetyan (Software Design Engineer) and Ned
Leave a Comment
  • Please add 6 and 8 and type the answer here:
  • Post
  • InfoPath makes it trivial to track totals for repeating structures, such as customer orders. Just create

  • How do I submit the form to the email using the browser version (form services in MOSS) I can do it in infopath but not in the web browser. I uses the email submit option.

  • I'm trying to use the formula shown in the text but it says that the field doesnt exist. And i'm changing the names of the fields to match the ones in my form. What can be wrong??

    Thanks

  • This function gives me an error referrence to undeclared namespace my:

    eval(eval(Skill[Skill_Level = "1"], 'concat(my:Skill_Name, ";")'), "..")

    It works if I take out the Skill_Level filter.   The exact same code works if I'm referencing a secondary data source dfs:.

    Ay ideas?

  • Problem with french infopath ;-)

  • PingBack from http://sebastianatar.wordpress.com/2008/12/29/method-for-populating-sharepoint-designer-workflow-email-with-multiple-recipients-from-contact-selector-control/

  • PingBack from http://www.keyongtech.com/1239900-get-all-values-of-dropdownlist

  • How about resolving emails conditionally? IE, if phone is blank do not resolve email in recipient line (or resolve nothing - "").

    I believe I will need to nest a substring function into the evals but i am at a total loss here. Any assistance is appreciated!!

  • PingBack from http://insomniacuresite.info/story.php?id=6264

  • I tried the "eval" approach but it's not working.  eval(eval(person, "concat(my:email, ';')"), "..")

    I'm using InfoPath 2003.  Below is the error I'm receiving:

    "my:Contributors/my:Contributors/my:Person/my:Email" does not point to a valid location path of a field or group.

    I have a repeating table that I need to be able to pull all email addresses from.  Please help!

  • Hi debb66,

    Please provide the data structure to your repeating table, such as like this:

    myFields

        group1

             group2 (this may be your repeating table)

                  NameField

                  EmailField

                  Etc.

    I need to get an overview of how your data source is setup.

    Scott

  • Thank you Scott:

    myfields

     Contributors

        People

           Person (repeating table)

             Email

    I have it in a section then repeating table.

  • Hi debb66,

    I am not sure what you mean by "I have it in a section then repeating table." So to be sure I am clear, now that I see the structure please do this:

    - Open your XSN in Design view

    - Display the Data Source Task Pane

    - Right-click on your "Email" node and choose Copy XPath

    Paste the XPath here so I can see the complete structure.

    Scott

  • Hi debb66,

    I decided to create the same data structure to see if this helps - here is what I have:

    myFields

        Contributors (Group, Non-Repeating)

             People (Group, Non-Repeating)

                  Person (Group, Repeating)

                      Email (Field)

    I then added a text box to my View simply to show the results - here is what I have as the default value for the text box:

    NOTE: If you want to copy/paste this make sure you enable the "Edit XPath" check box!

    substring(xdMath:Eval(xdMath:Eval(../my:Contributors/my:People/my:Person, 'concat(my:Email, ";")'), ".."), 1, string-length(xdMath:Eval(xdMath:Eval(../my:Contributors/my:People/my:Person, 'concat(my:Email, ";")'), "..")) - 1)

    When I Preview the form and add e-mail addresses to the "Email" field, each name in each row is added to the text box.

    Let me know if this helped!

    Scott

  • Scott:

    Thank you so much for  your quick response however, it didn't work...  Here's the error:

    MSXML5.DLL

    Reference to undeclared namespace prefix: 'my'.

    Error occurred during a call to property or method 'Eval'.

    I verified that the .dll is in place and sure enough it is.

    Thanks again for  your help.

Page 1 of 5 (62 items) 12345