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 60
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 8 and 7 and type the answer here:
  • Post
  • Hi debb66,

    Did you create the data source yourself or is it being created from an existing XML/XSD, database, etc. file?

    I just tested the same form using InfoPath 2003 and it worked fine.

    Scott

  • Hi Scott:

    I have to apologize I'm not a novice or programmer so you may have lost me.  

    I've created the form and have posted to a sharepoint site that collects the information.  I've not created a database, etc.

    I was hoping it was a matter of just copying and pasting the code.  Arrrggghh! :(

    Debbie

  • Hi Debbie,

    No problem - and you actually answered my question! :)

    If you would, do this for me:

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

    Thanks!

    Scott

  • Hi again Scott:

    I'm using 2003 InfoPath - it doesn't give me the Copy XPath option.

    Deb.

  • Hi Debbie...just consider me thick...I forgot you were using 2003. :)

    How about this:

    - On the View, drag an Expression Box and drop it outside of the section and repeating table (i.e. just somewhere in a clear area on the view)

    - Click the "Fx" button

    - Click Insert Field or Group

    - Drill down and select your Email field and click Ok

    - Enable the "Edit XPath" box on the Expression Box

    - Now, select and copy what is in the "Formula" box and post that here.

    Scott

  • You are a very patient person! :-)  Thank you!

    my:Contributors/my:People/my:Person/my:Email

    That is what I have.

  • Thanks Debbie!

    Well - what I gave you should definitely work. Unfortunately at this point, the best solution may be to open a support case so we can take a look at your XSN (and possibly at your machine) to try and see why this is failing.

    That XPath expression that you provided is identical to the sample I created on my 2003 machine and it works without issue...so something is going on in your environment.

    Do you have another machine where you can test this?

    Scott

  • I will try it on another machine and see what happens.  Again thank you for your help!  It is greatly appreciated!

  • Hi Scott:

    I tried a different machine unfortunately does not work.  So put in a helpdesk ticket to see what my IT group can do.  

    Thank you again for you patience and help!

    Debbie

  • Hi Debbie...

    That is quite odd...if your Help Desk runs into a wall, please don't hesitate to open a support incident with Microsoft so we can look at this for you.

    Scott

  • I have designed a form with a send button who has this formula: eval(eval(Adresslist; 'concat(@Email, ";")'); "..") where the Adresslist is a list on a share point server

    And it works just fine, but there seems to be a limit on 100 addresses in the formula or in the InfoPath send function and my list has 140 mail addresses so that the last 40 will not get the message.

    Can anyone tell me if there is such a limit in the formula or in InfoPath and how to make a workaround?

  • Hello,

    I am attempting this for the first time and am getting an error. I'm attempting to pull a list of email addresses based on what is selected in a Multiple-Selection List Box.

    My structure is (secondary data source - SQL DB)

    myFields

     dataFields

       d:tblDistributionListMembers

         :Contact_Name

    The error I'm getting:

    The following XPath expression is not valid: xdMath:Eval(xdMath:Eval(xdXDocument:GetDOM("tblDistributionListMembers")/dfs:myFields/dfs:dataFields/d:tblDistributionListMembers/@Contact_Name[../@Distribution_List = xdXDocument:get-DOM()/my:myFields/my:group6/my:group32/my:DistList], 'concat(my:Contact_Name, ";")'), "..")

    Any help would be greatly appreciated!

    Amber

  • Just wanted to say Thanks! I am a non-pragramming InfoPath newbie and this blog has been awesome!

  • Hello,

    This solution was a life saver for me a few months ago, but now the user wants a repeating section within a repeating section.  So instead of just delimiting the one repeating section, I now have to grab those other repeating fields and delimit them.  The reason I'm having to do this is to promote one long delimited field for a programmer to grab in order to create a report.

    Here is the structure:

    InstrumentDetails (group, repeating)

     InstrumentType (field)

       PayeeDetails (group, repeating)

         PayeeType (field)

    Can this be done?

    Thank you!

  • I have a similar (if not the same) problem to cahubin and I have been all over the internet and haven't found a solution. If I have a repeating section nested in another repeating section, and each has a drop down list, how do I access the selected elements of both? I want to grab the contents and shove them into a Rich Text box. Using eval(eval iterates through one repeating section. Is it possible to use another double eval to iterate through the outer repeating section? Please help!

Page 2 of 4 (60 items) 1234