Welcome to MSDN Blogs Sign in | Join | Help

InfoPath Team Blog

Tips and tricks to get the most out of Microsoft InfoPath

News

  • For questions, comments, and feedback please use the public newsgroup: microsoft.public.infopath
    This is provided "AS IS" with no warranties, and confers no rights. Use of included script samples and forms are subject to the terms specified in the Terms of Use.
Email Submit "To" line (loops in formulas)
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
Posted: Wednesday, April 05, 2006 2:54 PM by infopath
Filed under:

Comments

InfoPath Team Blog said:

InfoPath makes it trivial to track totals for repeating structures, such as customer orders. Just create

# December 4, 2006 11:05 AM

voquan said:

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.

# September 25, 2007 12:44 AM

abcoura said:

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

# January 17, 2008 8:49 AM

boverton said:

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?

# January 24, 2008 3:02 PM

n_thobois said:

Problem with french infopath ;-)

# June 25, 2008 11:49 AM

jtravism said:

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

# February 6, 2009 1:17 PM

debb66 said:

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!

# June 29, 2009 2:38 PM

infopath said:

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

# June 29, 2009 4:04 PM

debb66 said:

Thank you Scott:

myfields

 Contributors

    People

       Person (repeating table)

         Email

I have it in a section then repeating table.

# June 29, 2009 4:22 PM

infopath said:

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

# June 29, 2009 9:08 PM

infopath said:

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

# June 30, 2009 8:22 AM

debb66 said:

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.

# June 30, 2009 9:24 AM

infopath said:

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

# June 30, 2009 9:52 AM

debb66 said:

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

# June 30, 2009 1:55 PM

infopath said:

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

# June 30, 2009 2:15 PM

debb66 said:

Hi again Scott:

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

Deb.

# June 30, 2009 2:34 PM

infopath said:

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

# June 30, 2009 2:40 PM

debb66 said:

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

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

That is what I have.

# June 30, 2009 2:45 PM

infopath said:

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

# June 30, 2009 3:05 PM

debb66 said:

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

# June 30, 2009 3:19 PM

debb66 said:

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

# July 8, 2009 1:44 PM

infopath said:

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

# July 8, 2009 5:10 PM

Bressen said:

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?

# December 2, 2009 2:18 AM
Anonymous comments are disabled
Page view tracker