Pages

Thursday, July 9, 2009

Concatenating a repeating field into a single string in InfoPath 2007

Here's the scenario: You have an InfoPath form that contains a repeating table, and that table is used to capture names and email addresses. You'd like to create a workflow in SharePoint Designer that will email some information to the users you entered in the form. The only problem is SharePoint Designer doesn't have a loop function in the workflow creation wizard.

To get around the issue, we're going to use a little xpath function to concatenate the email address fields in the repeating table together, separated by a semi-colon - this will let us drop that list right into the TO line of an email.

The setup:
  • Create a new InfoPath form using a blank template.
  • Add the following fields to the main data source:

message_subject
message_body
people (group)
     person (repeating group)
          name
          email
recipient list



  • Drag the message_subject and message_body fields onto the form to create text boxes for them, then drag the person repeating group onto the form and select 'Repeating Table'. Then, drag an expression box onto the screen and bind it to the recipient_list field, and finally, drag a button onto the form. I've set the button's label to 'Get Recipients'. Your whole form should now look like this:
















  • Next, lets edit the button's properties and create a new rule to execute when the button is clicked. From the Button Properties dialog, under the General tab hit the 'Rules' button. Hit the 'Add...' button to create a new Rule. Leave the Condition set to 'None - This rule always applies', and hit the 'Add Action...' button.
  • In the Action dialog, choose 'Set a fields value' from the 'Action' box, and use the button to set the 'Field' to update as the recipient_list field.














  • Now, hit the Fx button to supply a function, and type this in the function box:
     eval(eval(person, 'concat(my:email, ";")'), "..")
  • NOTE: You will need to highlight person, then using the 'Insert Field or Group' button, insert the person group. In the end, it should be underlined. The rest of the statement can be typed in manually.












  • Click Ok to get all the way back out to your form.
  • Now its time to test!
  • Hit the Preview button to preview the form.
  • Enter a name and email address in the first row of the table, then click the 'Insert item' link and add a second name and address. Then click the 'Get Recipients' button, and the email addresses will be concatenated together and separated by a semi-colon.



Part II of this post will focus on creating a Workflow in SharePoint designer to send your message.

No comments:

Post a Comment