Alec Pojidaev's InfoPath Blog
Stuff published for no reason (cool codeless infopath solutions mostly)

Infopath codeless programming (walkthrough) 1

Special thanks: Karl D. Swartzendruber

Other parts: 2, 3.
Bookmark that post

Let me guess what might have brought you to that blog page about codeless programming in InfoPath. Any of you who developed at least one sophisticated InfoPath form sooner or later have been realized that writing forms with real complex behavior is impossible without some sort of coding in C# or VB.NET. So developers have no choice but to deal with mixed developing environment like Visual Studio, managing form security levels, security certificates and so on. But there are people who like to keep things simple. At least I do. And that’s why probably you are reading that page too:)

Anyway, lets get to the business. How to iterate an Infopath Repeating table?

Here is our scenario: we have a repeating group on the form which will be populated with wonderful (but often overlooked) Contact Selector Control with some user information. The control provides us all necessary information about user except his email.

But wait, that is outrageous! The email was the only reason why we decided to use that now not so awesome control! Well… at least we have access to the web service which able to return user email in exchange of account name. There are countless blogs describing how to utilize UserProfileService to get info of a single user in Contact Selector. Here I’ll try to demonstrate how to deal with multiple selection in Contact Selector. So now our task is clear – we have to construct a string acceptable in Email address field iterating through repeating group and submitting query to the web service on each cycle of iteration.

Let’s go.

The first things first – here using-the-contact-selector-control you will find detailed explanation how to utilize Contact Selector Control. The resulting data structure for the control in main data source should look like this

The Control also requires secondary data source

Add text field named HlinkToEmail. That field will hold result of our computations. Resulting Main Data Source:


When your new shiny control starts providing you users from your network that means we are ready for the web service part. Here we’ll use SharePoint GetUserProfileByName web method. You will need SharePoint Services running somewhere on your network. That part is pretty straightforward. Add secondary web service receive connection. Your link in connection settings should look like


The results of that part:

“Programming” part

Place a button on the layout. At Rules and Merge tab create rule named setfCounter. Press “Set Conditon”. In the first area choose “The expression”. Here is string to paste in second area:


The only action will assign initial value to the HlinkToEmail field. Press fx button at new action form. Check “Edit XPath (advanced)” checkbox. To avoid too detailed instructions of choosing functions and form elements just copy paste the following expression:

xdMath:Eval(xdMath:Eval(my:Person, 'concat(my:AccountId, "|")'), "..")

If you prefer more automated design (no button needed) the same expression above may be used as default value of the HlinkToEmail field.


At main data source pane double click at HlinkToEmail field. At Rules and Merge tab create rule named fConterRule. It’s a conditional rule. In the Set Condition dialog in the first area: Choose The expression. Then paste this expression into second area:

contains(., "|")

The resulting set of actions:


The rule will consist of 3 actions. The fist action will be setting AccountName field of data source named GetUserProfileByName to the portion of HlinkToEmail field. Check “Edit XPath (advanced)” checkbox. Paste Xpath expression:

substring-before(., "|")

Next is self-explanatory action. Add action -> Query using data connection -> Choose GetUserProfileByName.

Add the last action to set HlinkToEmail field to the new value by assigning following XPath expression:

concat(substring-after(., "|"), ";", xdXDocument:GetDOM("GetUserProfileByName")/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData/s0:Values/s0:ValueData/s0:Value[../../../s0:Name = "WorkEmail"])

We done with actions of that rule. Make sure that check box “Stop processing rules then this rule finishes” is checked.

Add the last rule right after fConterRule. In Set Condition dialog choose The expression. In expression area copy paste:

substring-before(., ";") = "" and contains(.,";")


And finally, set the HlinkToEmail to the following XPath expression:

substring-after(., ";")

That’s it.

P.S. Now you know how to iterate and read repeating structures. But what if you need to write? Well, InfoPath doesn’t provide UI to parameterize repeating structures are assigned to new values. Still here you will find a workaround which overcomes this limitation.

Posted under tags: MOSS Contact Selector Control Infopath Sharepoint

170 Responses to “Infopath codeless programming (walkthrough) 1”

  1. Good stuff – glad we were all able to work together to improve this solution and come up with a way to do it for InfoPath-only emails and for using SPD workflows to send the emails. Have you considered splitting it into those two sub-categories? The way I’m doing it for SPD is unbelievably simple compared to these steps, although yours are excellent.

  2. Special thanks part is at the top and updated :) Sending emails in workflow is a good and legitimate practice. But my initial goal was just to show how “state automates” programming principles could be applied bringing significant advantages such as easy of deployment. After all 3 rules and 5 actions is not that big amount of work. :)

  3. hi,

    I am using Contract Selector to send an email to selected personals and/or groups. it works if we select persons in contact selector but not for groups! Any idea???

    • There is SharePoint service which returns all members of a given SharePoint group. There are also bunch of Exchange server webservices (not tryed them yet). Getting information directly from AD will require to write custom webservice. Anyway combining web service data with that solution will allow to solve your problem.

  4. Is there a way to send an email to the manager of the person’s name in the contact selector?

  5. To: Nick
    Shouldn’t be a problem. For example if you’ll replace “WorkEmail” with “Manager” in the main action like this:

    concat(substring-after(., “|”), “;”, xdXDocument:GetDOM(“GetUserProfileByName”)/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData/s0:Values/s0:ValueData/s0:Value[../../../s0:Name = “Manager”])

    you will get concatenated string of managers AD accounts. Applying same method to the resulting string again you will get managers emails. In between those 2 steps you will need to replace separator from “;” back to “|” with ‘translate’ function to make it work.

    When you will have better understandiing of how does it work you will be able to fit everything in one rule.

  6. Well written post. It’s nice to see more people using InfoPath’s built in functionality without resorting to code right away. :)

  7. Great post. It works perfectly for me. One question though, have you tried setting this up to work with two Contact Selectors on a form pulling in the profile information for two different users? I’m trying to get that to work but the second set of fields always pulls the first set of profile data.

    If you have any ideas that would be awesome!

  8. I have tried this solution and got it to work perfectly in my test environment. When I published it to the production server, though, everything went to hell. I have some users who even farm administrators cannot retrieve the email for, and other users who aren’t administrators can’t retrieve ANYONE’s email? I have searched for information on security and permissions for the userprofileservice.asmx, and can’t find anything about this at all.

    The error message I get in all these instances is:

    The query cannot be run for the following DataObject: GetUserProfileByName
    InfoPath cannot run the specified query.
    The SOAP response indicates that an error occurred:

    A user with the account name DOMAIN\username could not be found. —> User Not Found: Could not load profile data from the database.

    The production server is part of an enormous AD forest, with over 300K users, but I’ve found 2 users so far that nobody can retrieve a profile for, even though they’re members of the sharepoint site collection and have a profile.

    • It’s understandable why admins are having problems. It’s because they recognized as SystemAccount and there is no such record in AD or user profile database.
      I dont know what causing your problem. Over all it doesn’t look like InfoPath specific problem. The only suggestion I have is to convert UserProfile connection and then navigate to Connection library and approve resulting *.udcx file.

  9. Hi,
    I’ve used this control and it works great. My challenge is that I need 2 of these controls in my form. I could achieve this by creating the “gpContactSelector” in a repeating group, but I don’t want the users to add more than 2. Is this possible? How?

    • I dont think its reasonable to create repeating group for 2 repeating elements. If your second control is optional you could put it in a section and apply conditional formatting (hide/unhide) in responce of an user action.

  10. Hello Alec,
    I guess I didn’t explain the situation very well. Basically, I need to have a Contact Selector for “Employee”, and one for “Manager”. An alternative would be to automatically pull the employee’s manager from AD (but have not explore that option yet).

    So, for this I followed the instructions mentioned in the blog: (see Oct 08, 2007), it says that you can have multiple Contact Selector fields by having a repeating group, but it does not limit the number these fields, and I only need 2. I tried to have another instance in my datasource but didn’t work because I must maintain the names of the fields, otherwise I believe it does not work.

    Any guidance on resolving my needs (1 employee, 1 manager in separate fields) would be much appreciated.


  11. I’ve tried this solution and it worked great while using it with infopath.
    But I’ve some problems publishing the form to MOSS with office forms server. When I try to select a Person, the HlinktoEmail only shows the email of the user that is currently logged on to MOSS – not the one that I’ve selected in contact selector…
    Can somebody please tell me what’s going wrong??



  12. Never have expirienced that kind of problem before. It works fine in MOSS for me. Just make sure you moved all actions from Contact Selector to any other control.

  13. I completed these steps, but I don’t get any different results with my people picker than before. I have my people picker on the form and immediately afterwards I placed the HlinkToEmail text box. Am I supposed to see the associated e-mail address in the text box? I need to be able to determine if the contact selected has an associated e-mail address (because our AD has some with and some without.

    FYi, I’m not a programmer. I was successful in creating 2 separate people pickers on the same form, but now I need to insure there are related e-mail addresses attached to the user’s selections. I’m sure either I did something wrong, or I’m expecting something to happen that wont. The only difference I see is when I say set the HlinkToEmail field to a new value – because I’m already in that field, the rsulting formula only shows a “.” to indicate the field is the same. Thank you in advance. DAP

  14. To: Donald

    >Am I supposed to see the associated e-mail address in the text box?

    The “.” is supposed to be in the fields name. It means “self”. Then in the formula field you have to paste Xpath expression.

  15. I pasted the Xpath expression in to begin with and then InfoPath reformats it somehow to what it likes. If I click the xPath check box the formula changes back and forth to the xPath formula and a simplified version InfoPath determines. Is there something else I can check? I went back and reviewed your instructions again and all seems well – just doesn’t give me an e-mail address. I deliberately pick a contact that has one listed, to ensure I get the desired results.

  16. So what exactly you are getting in HLinktoEmail field after choosing a person?

  17. I’m getting the same results as Stefan. I published the browser-enabled form to my MOSS site. When the form is displayed in InfoPath, HlinkToEmail shows the email addresses for the Person names entered. When the form is displayed via the form server, HlinkToEmail shows the logged on user. This is a simple form with just the Contact Selector and HlinkToEmail fields.

  18. To Mike:
    Have you moved all actions from Contact Selector to any other control?

  19. No. Does it matter which control I move them to?

  20. Any control will work (exept Contact Selector). The XPath will differ a bit:

    xdMath:Eval(xdMath:Eval(../my:replyToControl/my:Person, ‘concat(my:AccountId, “|”)’), “..”)

  21. I don’t get anything in the HlinkToEmail field. Not only that, but I can’t even click in the HlinkToEmail field to manually enter anything (not that I want to, I just find it odd – it acks like a read-only field). Keep in mind that I can also enter multiple contacts, even though I made the 3 sub fields non-repeating. I can send screen shots via e-mail if needed.

  22. Everything looks correct. The only problem is your formula. Try to make it work with any repeating structure. There is alot of info on internet discribing in much better way than I did how to use double eval.

  23. What is this double eval trying to do? I may be able to get it to work if I know what HlinkToEmail is expecting to receive to further process the data.

  24. It should return concatenated string of AccointId’s in form of:
    domain\user1|domain\user2 …domain\user10| .The last symbol should be “|”

  25. Thanks for the great tutorial! I’m also having trouble when publishing my form as browser enabled (same as Mike and Stefen). I’ve even transfered the actions from the contact selector group to a field on my form. Do you mind posting additional details or tutorial on how you got it to work? Any help greatly appreciated!

  26. To Dennis:

    What exactly is your problem?

    • When I preview as an infopath form, the contact selector works as it should, pulling the email of the person selected. Once published to sharepoint (browser enabled), a person is searched and selected but grabs the email of the person using the form (different from the person selected). As suggested in one of the post, I’ve even transfered the rule and all the actions from the contact selector to a field on the form and still no luck. Any guidance, examples, or even additional screen shots is greatly appreciated. Thanks for your time.

  27. To Dennis:

    > I’ve even transfered the rule and all the actions from the
    > contact selector to a field on the form and still no luck.

    Please be specific. What do you mean when you saying “no luck”? What happened when you pressed/typed in control you’ve transferred actions to?

  28. Side question – where is this ‘coding’ information documented?
    For example, “xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”) ”

    xdMath? Eval?

  29. Good question. I did a small research myself and, to my amusement, found nothing on Microsoft MSDN site (although there are few examples which uses that namespace).

    If you will find more info please post it here. Looks like it’s a good reason to solicit Microsoft to fix that gap in documentation.

  30. Thank you for this stuff, here was two issues I’ve search for a while and it helps a lot for my current bussines project.
    It’s an amazing beautyful concept. I mean codeless programming by InfoPath.

  31. Has anyone successfully move all three rules to a control (like a button control) before?
    I am trying right now and i can’t get pass the expression:
    xdMath:Eval(xdMath:Eval(../my:gpContactSelector/my:Person, ‘ concat(my:AccountId, “|”)’), “..”)
    Error said:
    Reference to undeclared namespace prefix: ‘my’.
    Error occurred during a call to property or method ‘Eval’.
    Love to hear from the experts

  32. It seemed to run but my HlinkToEmail textbox return empty eventhough my selected 3 names in the contact selector.
    Here is my setfCounter rule:
    xdMath:Eval(xdMath:Eval(my:gpContactSelector/my:Person, ‘concat(my:AccountId, “|”)’), “..”)

    Here is my fCounterRule:
    concat(substring-after(., “|”), “;”, xdXDocument:GetDOM(“GetUserProfileByName”)/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData/s0:Values/s0:ValueData/s0:Value[../../../s0:Name = “WorkEmail”])

    did you do something wrong?

  33. one more time:

  34. That won’t work.

    The only action you need to move to the button is with eval function. The other rules has to stay where they are – at field control.

  35. Well i left the frist rules there for the button and move the bottom two rules to the HlinkToEmail textbox field and the result still the same nothing on the textbox field when i click the button.

  36. Make both rules on the field disabled to see if string of users properly populated by the button rule.

  37. I took the 2 rules from the HlinkToEmail textbox field away and the result still empty. so there is something with my first rule.
    Condition of the first rule set to:

    Set a field’s value: HLinkToEmail=xdMath:Eval(xdMath:Eval(my:gpContactSelector/my:Person, ‘concat(my:AccountId, “|”)’), “..”)
    with Edit XPath (advanced) check box checked.

  38. Check if anything is wrong with condition. Remove it from button rule.

  39. I tried to debug through your example and i notice that i have twice the list of email addresses and when i trace back to the rule that use for the contact selector control i notice i got the list of AccountId listed twice and therefore the email address listed twice. I can’t seem to explained why?
    Here is the rule used in my contact selector control:
    eval(eval(Person, ‘concat(my:AccountId, “|”)’), “..”)

  40. That means the event fires twice. But if you have moved all rules from contact selector to a button that kind of thing shouldn’t happened.

  41. I could not get the button to work. I would like to clarify a few things:
    As i understand there were total 3 rules mentioned in your example (setfCounter,fConterRule and RemoveChar) setfCounter rule used in the contact selector control and the other 2 rules used in the HLinkToEmail textbox. So i added a button and moved the setfCounter rule from the contact selector to the button. The other 2 rules stay with the HLinkToEmail textbox. Am i correct so far? When moving the setfCounter rule to the button i made the change according to some of your reply this past Friday as follow:
    eval(eval(my:gpContactSelector/my:Person, ‘concat(my:AccountId, “|”)’), “..”)
    That is where i am at. When i try to run it after selecting all names and click the button i got nothing in the textbox.

  42. You getting nothing in textbox when rules on textbox desabled(unchecked) or with both rules checked?

  43. I got nothing regardless whethere there are rules in textbox or not. I think the setfCounter rule doesn’t work. I am suspecting of the condition for the setfCounter rule. I could not get it to say:
    Number of occurrences of Person > 0

    Here is mine:

  44. Finally i got it to work with condition applied. but the only problem i saw was that the some of the AcountId were not resolved to the approriate email.
    Here is the list of accountId (which is correct)

    Here is the list of email:

    As you can see, the last AccountId was not resolved and the warning/error was:

  45. It should be configuration problem. It’s hard to say what it could be.

  46. worked on Some AccountId’s and did not work on some others. Do you have any tips as where to look this kind of configuration problem? This blog is great and i learned so much.

  47. Hi Alec, Got one problem, when performing the step xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”) , it gives an error with the formular. I’m very new to this so prob missing something small. Any advice? Bellow is a copy of the error.
    Unexpected character.
    xdMath:Eval(xdMath:Eval(my:Person, –>‘<–concat(my:AccountId, "|")’), "..")

    • That’s really simple. That symbol you having trouble with designated to indicate single quot. However the symbol itself is not a single quot. So just delete it and replace with real single quot symbol.

  48. Yes you were correct and i have found that to be the problem as well. One side affect that i have seen was that eventhough if i did not enter any name in the contact selector control the HLinkToEmail still list one email address which is email address of the person with the current logged-in account id. I looks like the condition for the contact selector rule: Number of occurences Person >0 did not execute correctly.
    I was trying to create a template part for this contact selector control since i am using quite often in my forms but it seem that it is not doable since the control is always disabled in the template part design mode. Do you know if it is posible to that? i can’t seem to be able to add the control to a template part.

  49. Well.. I never used templates parts so I can’t help you here. I would be interested in final results of your attempts though. Please post here if you were succeseful.

    • Thats how it should be. Initially group always have one node so check will be always be true unless you will delete that initial node manually. The condition serves to prevent to fire the event wich will errors out without that condition.

  50. One side affect that i have seen was that eventhough if i did not enter any name in the contact selector control the HLinkToEmail still list one email address which is email address of the person with the current logged-in account id. I looks like the condition for the contact selector rule: Number of occurences Person >0 did not execute correctly.
    Have you seen it?

  51. i have seen the same issue and when i moved the rule from contact selector to a button it worked.

  52. And the condition of this rule should say:
    Number of occurences of Person > 0

  53. By the way, can this control be adaptive to different situation? I have a need to allow the user to select multiple item in the dropdown list box in my form, since multiple selection list box is not supported in browser-enabled, can i adapt this contact selector for that situation? if not is there a work around with my situation? thank you in advance

  54. The workaround is not that complex. Use repeating section/table with checkboxes-values pairs and then apply double eval trick same as in this article to get string of values where checkboxes are checked separated with a separator of your choice

  55. Hi.

    Great post and implemented. However I in browser I am getting the same issue as Dennis. You said
    “Note: There is a problem with browserenabled forms. Rules at Contact Selector provide totally unpredictable results. So to make it work I’ve moved all Contact Selector rules to a simple button.”

    How do I move these to a simple button please.

  56. Hi

    Thanks for the help I still get

    Reference to undeclared namespace prefix: ‘my’.

    Error occurred during a call to property or method ‘Eval’.

    This is the rule

    xdMath:Eval(xdMath:Eval(my:replyToControl/my:Person, ‘concat(my:AccountId, “|”)’), “..”)

  57. Wow thanks for this solution! I have tried and tried and finally I found this. But when you give the NOTE at the end for browser-enabled forms, and you say : “So to make it work I’ve moved all Contact Selector rules to a simple button.”…..

    what do you mean by moving all rules to a button? Can you show me how to do this?


    • Edit: actually I desided to excude all parts of description that doesn’t work in browser. Check out XPath/layout changes.

      The action with this rule:

      xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”)

      should be moved to any other control. The final XPath will be different depending on what control the formula and it’s condition (count(./my:Person)>0) will be moved (i.e. the relative XPath at a field to the my:Person group differs from XPath at a button because buttons are closer to the root)

  58. Hi Alec, great post! I’ve read through all the conversations and I am also getting the:

    Reference to undeclared namespace prefix: ‘my’.

    Error occurred during a call to property or method ‘Eval’.

    error. I am using a button. I have the count-person condition and the eval rule on this button. Any ideas?

  59. Yep I have the latest xpath formula:
    xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”)

    I have more than one contact selectors so I also tried:

    xdMath:Eval(xdMath:Eval(../my:A12participants/my:A12participant1/my:Person, ‘concat(my:AccountId, “|”)’), “..”)

    Still no luck. Here is part of my data source structure:


    Any ideas?

  60. The cap “D” was my mistake when replying to you. It is actually lowerces in the form. I tried taking the “../” out and I also tried “./”. I also tried choosing it from the field picker. No dice. Anything else I should do?

  61. No. A12participants and A12Participant1 are not repeating groups. Does it matter how I setup the other contact selectors?

  62. Hi Alec,
    I have used this formula to obtain a list of email from a repeating table:
    eval(eval(GrpTechDept; ‘concat(my:TechEmail, “;”)’); “..”)
    I got a resulting list like this:
    Now I would like to remove the duplicate email from this list. Is there a trick to improve the formula above to prevent concatenating duplicate value (codeless of course).
    Thank you in advance. Kind regards,

  63. As I am attempting to set the rule in the button, InfoPath 2007 says there is an incorrect character in your expression:

    xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”)

    It points to the ‘ before concat but if I remove it there are more errors

    Sorry to be a bother on this, but it is not very intuitive

    • you have to replace single quote with actual sign. The copied string has sign used in HTML pages and it’s not a single quot it’s just looks similar.

      Edit: I’ve replaced wrong quotes right in the post.

  64. First, thank you for posting this solution, incredibly helpful. :)

    It seems that my form is not iterating through the list of contacts I select in the Contact Selector. I cannot figure out why. Has anyone else had issues with this? The text that generates is just the first contact’s information repeated for each contact I selected.
    I.E. I select: Doe, John; Jane, Smith; Bob, Brown
    Text generated:;;

    Please let me know if you have any thoughts, thank you!

    • Check what account name you are supplying to the websevice.

      • Sorry, I’m new to using InfoPath, how would I check that?

        If you mean the AccountName=substring-before part, the AccountName is supplied from GetUserProfileByName data source, under the myFields, queryFields, s0:GetUserProfileByName.

        I seem to have issues before the part that converts the AccountIDs to email addresses. If I remove all of the rules assigned to the HlinkToEmail field and only keep the rules attached to the button, the text box returns something like: ACUS\E10091|ACUS\E10091|ACUS\E10091
        So it seems to recognize that there are three contacts I’m trying to pull, but it only retrieves the AccountID of the first contact? Any thought?

        Thank you!

      • If ACUS\E10091|ACUS\E10091|ACUS\E10091 is the string returned by double eval formula where all accounts are the same that means there is an error in your version of this formula: xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”).

      • This is my formula:
        xdMath:Eval(xdMath:Eval(/my:myFields/my:gpCopyToContacts/my:Person, ‘concat(/my:myFields/my:gpCopyToContacts/my:Person/my:AccountId, “|”)’), “..”)
        Where gpCopyToContacts is my Contact Selector. Rather messy, I know. As far as I can tell, it seems to replicate your formula, just with different XPaths for my Contact Selector. Am I referencing my:Person and my:AccountId incorrectly?

      • That part: (/my:myFields/my:gpCopyToContacts/my:Person/my:AccountId is incorrect.
        The path to the field has to be relative not absolute.It should be much shorter: (my:AccountId

      • Excellent! That was it! Thank you so much!

  65. msxml5.dll reports undeclared prefix ‘my’ when I try to assign the Text field the value of xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”)

  66. Thanks for sharing us your solution, i’m very greatful :) (F)

  67. Can this be modified to work on a repeating field?

    Great tool for repeating groups, but in my situation I’m using a multiple selection list box because I’m displaying from a list and want the users to be able to just check the names to be contacted.

  68. Hi Alec,

    I’m just writing to say thanks for taking the time and putting this together. It works like a charm and is very helpful.

    Although it works, I’m curious to know how/why it works so that I understand it better. My understanding is the following string is set as the value of the “AccountName” field of the GetUserProfileByName data source.

    substring-before(., “|”)

    After running the query, the webservice returns necessary information. Now, to me, that looks like getting the very first username returned by the contact selector tool. Where does the actual iteration take place? I’m not clear on how the rule is looping through all the username and then query the data source.


    • To pl7626:
      The iteration is happening when the HlinkToEmail gets a new value. What actually formula at HlinkToEmail field does is it removes the user before “|” and adds the removed user’s email to the end of the string. Thats triggers the next iteration. Thus each iteration removes one “|” delimeter per cycle. As you can see to prevent infinite loop the condition is checking for existence of “|” separator.

      • Hi Alec,

        Thanks for replying on this. Now that you explained this, it looks so simple. I should’ve paid more attention to the formula that sets value on the HlinkToEmail field :)

        It’s a really nice trick and opens a whole new door to iterating through repeating stuff using just rules.

        Thanks again. It’ll be really useful.

  69. Hello! I went thru the proceedures listed. Unfortuantely, I can not figue out how to hook up all of this to my 3 Person Group Picker fields. I am usnig InfoPath 2010. My purpose is to set up a rule so when a user clicks on my custom submit button on the form, the emails get sent to the choosen individuals. As you know, by default the fields populate with Kreuder, William and the system does not recognize this as an email. Thanks!

  70. My situation is quite simpler (no contact selector control) but i can’t get it to give me the list of comma seperated email addresses from the sharepoint server list. Here is what i have done:
    1. Adding a new “data connection to receive data from SharePoint library or List” where i selected Email Address column of the contact list.
    2. I added a new Text Field and define a new rule with “Query using a data connection” defined above.
    3. I defined a rule in my Text field with two actions like these:
    Query using a data connection:GetEmailAddress
    =fx Set a field value:.=concat(.,”,”,@EmailAddress)
    What am i doing wrong? Thank you in advance. Really can use the help to get it to work since I am pressure for time

  71. how would you formulate the double eval? can you help?

  72. i put this code concat(@EmailAddress, “,”) in the value of the Text box then i got the first emailaddress (which id ok) but if i want to use the double eval for repeating group (see below) then i got an error saying: Infopath cannot open the selected form. Obviously there is some thing wrong my double eval statement but i can’t seem to see it.

    my double eval:
    eval(eval(RoeDataEntryNotifiers, ‘concat(xdXDocument:GetDOM(“GetDefaultReceivers”)/dfs:myFields/dfs:dataFields/dfs:RoeDataEntryNotifiers/@EmailAddress, “,”)’), “..”)

    where RoeDataEntryNotifiers is a repeating group for my data connection which query the list of sharepoint server.

  73. And if i put the double eval in the rule section of the text box then the form displayed but i got nothing in the textbox field.

    my double eval:
    eval(eval(RoeDataEntryNotifiers, ‘concat(xdXDocument:GetDOM(“GetDefaultReceivers”)/dfs:myFields/dfs:dataFields/dfs:RoeDataEntryNotifiers/@EmailAddress, “,”)’), “..”)

    • Try this, this works for me.

      You don’t need any rules, just paste it into the value field inside the properties section of your text box.

      eval(eval(Person, ‘concat(substring-after(my:AccountId, “\”), “; “)’), “..”)

      Select fx then highlight Person, insert field or group and select person from under the contact selector that you are using.

      This should work for you too.

  74. It worked. Thank you very much.

  75. This stuff is really helpful. Thanks! However, I am putting up a new form where I can use the same technique discussed here but with a twist… I’m not using contact selector and if there are identical email addresses, only one should be added to the HlinkToEmail field.
    Hope to hear from you soon.

    • The duplicated address never been a problem because all modern mail servers are able to recognize duplicates and trim them. So people never will recieve duplicates of the same email. If you still need to address that isssue you could use validation rule based on technique described here to validate user input.

      • I appreciate the quick response. If duplicates get automatically trimmed then I guess I don’t have to worry about it then. Thanks again!

  76. Hello Alec,

    Could you please help me with my problem? I am using this to set a text field when a button is clicked. I am using Person/Group picker – multiple select enabled (InfoPath 2010).

    eval(eval(Person, ‘concat(/my:myFields/my:PointOfContacts/pc:Person/pc:AccountId, “|”)’), “..”)

    First of all, I am not sure why the prefix is “pc” and not “my”.
    Second this is that when I click the button to populate the text field, I get the AccountId of the first user repeated so many times (depending on how many users I have in the Person/Group picker control).

  77. I’m trying to design a form where users can optionally CC a copy of the form to someone else (the default destination is the same for everyone). I’ve gone through and set everything up the way you explained, and didn’t get any errors, and set HlinkToEmail as the cc address in my submission data connection.

    Problem is, nothing happens. Put HlinkToEmail onto the form as a text box, and disabled all the other rules on the Submit button, but nothing happens. If I create a rule that says ‘Change the value of HlinkToEmail to: “Yarg!”‘, then when I click the button, “Yarg!” appears in the HlinkToEmail box. But with the rules I created from this article, nothing ever appears in the box.

    I’m not terribly familiar with InfoPath, so I don’t know if I’m just being unusually dense, or if there a step somewhere I’m missing. Any help would be much appreciated.

    • You shouldn’t put that functionality on the submit button. The best way to design this form is to use default value of HlinkToEmail, not rule at the button. Assign this formula from the post as HlinkToEmail default value:
      xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”)
      At the time when you’ll need to submit the form the emails will be ready.

  78. Is it possible to download the soultion file?

  79. Like Michael i`m having a problem with the Eval pointing to a Person field. In my case i tried to use the formula as alecpojidaev says: eval(eval(Person; ‘concat(pc:AccountId, “|”)’); “..”) but in my case i got a error that says: “Reference to undeclared namespace prefix: ‘pc’.Error occurred during a call to property or method ‘Eval’. “. I should also state that my Person group is inside a sharepoint list that a i use as a secondary data source.

    Thanks in advance

  80. Great Post!

    It works fine for me when I send the email fro the first time. However, when I reopen the form and attempt to send the email again after making fre updated I am getting an error. The HToEMailLink is storing someother value instead of the email address.

    Could you please help me to resolve this?


  81. Hi ,

    Thank you for the great article on using-the-contact-selector-control. I was able to implement it successfully but now I want to add multiple contact selector in the same form. I did add the reference of the contact selector created and tried setting the HlinkToEmail but it sets the value to DOMAINNAME\login name and gives following error:
    The query cannot be run for the following DataObject: GetUserProfileByName
    InfoPath cannot run the specified query.
    The SOAP response indicates that an error occurred:

    A user with the account name true could not be found. —> User Not Found: Could not load profile data from the database.

    • You requesting the profile info of the user with name “true”. Do you have this user in your organization?

      • Thanks for the reply. Yes the employee is in to organization and I am able to pull the details in the fisrt contact selector but the secound contact selector throws an error.

        I created a group and then added the reference of the fisrt contact selector and replicated the same steps in the article.

        When is lookup it shows the employee and get the domain and login id in textbox.

        Not able to figure out where it is gng wrong because it works for the 1st contact selector. Need help!!

        Also can you suggest some good books to buy for infopath 2007 programing and sharepoint workflow programing.

      • Is “true” the last name or the first name of your user?

  82. No.
    But Alec, I am able to lookup the same employee in the 1st contact selector but not in the 2nd selector. It just gives the domain\login name as output in the text box with error.

    I even tried selecting different employee and its the same error.

    Please help!!!

    • No?

      The error message clearly indicates that you submitting the string “true” to the service instead of valid username.

      • I am new to InfoPath programing and I dont know from where it is pulling up the account name “true” though the output in the textbox is domain\login id. Does it use this output to search the the work email?

        The 1st contact selector is working fine with no errors.So I think I am messing arround in creating/configuring the 2nd contact selector.

        I followed the following steps in creating the 2nd contact selector:

        1. Created group filed.
        2. Added the contact selector control
        3.Then added the reference of the first contact selector to group field
        4. Bind the newly added contact selector to referenced ontact selector
        4. Then followed the above article.

        Please let me know where exactly i am going wrong or how can we have multiple contact selector controls in the same form.

  83. Hi Alec,

    Hey , its working for me now :) . Its was just typo error in the rule which sets the AccountName. Thank you for this great post! You made my work lot easier!

    Can you suggest some good refrence book for Infopath programing and also sharepoint for beginners.

    Once again thanks for this gr8 article!

    • Sorry, I cannot recommend any good book. I learned both InfoPath and Sharepoint using Google query string.

      • Dats fine Alec,

        I have an issue with the control when the form is displayed in web browser(pulishing it to open in browser)

        Its does not populate the HlinkToEmail with the search account name but it sets the HlinkToEmail to email id of the user logged in twice.
        For the 1st serach Click in contact selector
        For 2nd Account Search;
        Do we need to change the rules to use contact selector for browser enabled IP form?
        The above rules work fine when we open it in InfoPath Client.

        Please Help!

      • No changes required for browser enabled forms. Such behaivior like in your situation is common when you submitting the empty string to the service.

  84. But Alec, I tried opening the pubilshed form in the client instead of Browser and It works fine.

    And If I change the settings of the form Library to open the form to browser again the output is duplicate ids though it searches for the right User and displays the name in the Contact Selector but the textbox takes the email id based windows logon for 1st search, and then second time we lookup it appends the serached email id and the old value in the text box.

    And on third try it gives the following o/p:
    Contact Slector values : Abc,Smith;xyz,Test
    Textbox value:;;;

    So how is it possible for the contact selector to assign blank value to AccountName when we have name displayed in the Contact Selector?

    I am trying to debug the rules….but no luck so far….

    It is working fine when we open it InfoPath Client from the library.

    Please reply!

    • How you assigning the initial value to the HLinktoemail field by rule or as default value?

      • Using the below rule:


        xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”)

        and the above rule is set on the myContactSelector group filed which is binded to contact selector:

      • Alec , I have still not found the solution for it! I am trying to check output of each actions in the rules…no breakthrough as of now :(..Please help!

  85. This was a great post. The only question I have is when the form is re-opened the HlinkToEmail field is showing as the Domain/Username. How can I avoid this from occurring? I would still like the email address to be presnt.

    • You are the first who is experiencing such problem. That makes me think that values are changed by external process like workflow or other rules.

      • I have this being set as the default value in the HlinkToEmail field.

        xdMath:Eval(xdMath:Eval(../my:ControlSelector/my:Person, ‘concat(my:AccountId, “|”)’), “..”)

        Does that look correct?

        Whenever I choose a value from the control selector the email is being populated in the HLinkToEmail field, but as soon as I save a re-open the form the HLinkToEmail fiedl now has Domain/Username. I think it has to deal with the default value.

  86. Hello,

    Its agreat tutorial. But I get the following error when I try to set the defau value of the text box. The formula I am using is
    xdMath:Eval(xdMath:Eval../my:group7/my:group8/my:group_3/pc:Person,’concat(../my:group7/my:group8/my:group_3/pc:Person/pc:AccountId, “;”)’), “..”)



    Reference to undeclared namespace prefix: ‘pc’.

    Error occurred during a call to property or method ‘Eval’.

    Do you think I am missing something. Also want to ask what is the data source “Context(secondary)” mentioned in the article(which a picture)?

    • xdMath:Eval(xdMath:Eval../my:group7/my:group8/my:group_3/pc:Person,’concat(../my:group7/my:group8/my:group_3/pc:Person/pc:AccountId, “;”)’), “..”)
      Left parentesis is missing after second Eval. The field addres is incorrect too. Shoud be:
      ’concat(pc:AccountId, “;”)

  87. The eval method helped me out really….Thanks

  88. By default it displays the email ID of the current user in the field (when the rules SetfConter and RemoveChar is added to text field instead of button)

    Please let me know how to get rid of this value when form is loaded

  89. Hello,

    I’m eager to get this working. This is awesome information. Has anyone else had this error?

    “xdXDocument:GetDOM(“GetUserProfileByName”)/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData/s0:Name” does not point to a valid location path of a field or group.

    What can I do to get rid of this error?



  90. Hey man,

    Inspiring stuff. If I can get over the minor hurdle I have fo rhtis, I will be able to kill two birds with your stone here.

    Not modifying anything, when I use (turned edit xpath on):
    xdMath:Eval(xdMath:Eval(../../my:InitialView/my:NotifyList_IV/pc:Person, ‘concat(../../my:InitialView/my:NotifyList_IV/pc:Person/pc:AccountId, “|”)’), “..”)

    I get as an error:
    “../../my:InitialView/my:InitialView/my:NotifyList_IV/pc:Person/pc:AccountId” does not point to a valid location path of a field or group.

    I’ve shifted to using my:AccountID, using the Insert Field to insert the AccountID field, I’ve even used a completely different field unrelated to this task just to test it out, and I keep getting this error.

    Any ideas?

  91. I still can’t figure this out. Here’s what I have
    for the button
    xdMath:Eval(xdMath:Eval(my:gpContactSelector/my:Person, ‘concat(my:gpContactSelector/my:Person/my:AccountId, “|”)’), “..”)

    “my:gpContactSelector/my:Person/my:gpContactSelector/my:Person/my:AccountId” does not point to a valid location path of a field or group.

  92. Hi Alex,

    I have a set of names divided by semicolons

    John Doe; Jane Winn

    that I know I can add to a contact control to show up there as long as I add the correct XML:

    John DoeJane Winn</my:gpTeam

    How can I do that with browser form xpath?



  93. I have a form setup where I can add multpile people to the contact selector. I have the steps in this forum, but when I click the button to display the email addresses, it only show the first person name that I enter. How do I fix this?

  94. I have followed all the steps with the contact selector and the context. but when i clicked the To button and search for a name i get search failed. any idea from where i can solve this.

  95. This worked perfectly in my sharepoint 2010 and infopath 2010 implementation. Do you have a suggestion on how I can submit the form to the email address calculated via HLinktoEmail?

  96. I tried that but it doesn’t work.

  97. This solution is not working for me in SharePoint Claims authentication I think becuase of the AccountId format.

    Also the Action rules on person (repeating control) in Infopath 2010 does not show up in Manage rules but displays it in Rule Inspector with “error in processing”.
    xdMath:Eval(xdMath:Eval(my:Person, ‘concat(my:AccountId, “|”)’), “..”)

    I am able to get only first user email id by changing the below rules:

    contains(., “i:0#.w|”)

    substring-before(substring-after(., “i:0#.w|”),”|”)

    Please help!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: