vrijdag 23 maart 2012

Save multiple accounts in SharePoint people column

This is a post about storing the data from an InfoPath Contact Selector control into SharePoint, in a proper way without coding.

It is very useful that when you have a K2 workflow with an InfoPath form, you want to store or synchronize the form data with a SharePoint item. I ran into an issue with saving multiple user accounts from a Contact Selector control. All accounts entered in this InfoPath control must be saved with the corresponding SharePoint item. K2 must update the metadata of the SharePoint item when the user submits the InfoPath form.

Your InfoPath form contains a Contact Selector in which multiple user accounts can be added.



Now, let's store the user accounts (Bremen, Onderwater, Schepers) with the SharePoint list item (see the screenshot below).


At first glance, it seems like this is not possible. I have found something that can do the trick, and the best thing about it: no coding is needed!

In you are familiar with the Contact Selector you know that InfoPath has the following fields in the main data source: a Person group that contains the nodes DisplayName, AccountId and AccountType. Please read the following page if you don't know how to configure the Contact Selector: http://msdn.microsoft.com/en-us/library/ms558892.aspx.



In SharePoint you need to create a column to store the user accounts. In my example I name this column 'Experts'. Please note that you need to check the 'Allow multiple selections' option.


Now go to your K2 workflow and create two activities.


For the first activity (Extract experts) plan the Destination Users according the options below:
  • Run this wizard in Advanced Mode;
  • Plan per destination - All at once;
  • Create a slot for each destination;
  • Resolve all roles and groups to users;
  • Add a destination set by using the AccountId node of the InfoPath Contact Selector


Create a data field of the type String. In my example I name this field 'Experts'.

Add a Data Event to the first activity. This Data Event fills the data field 'Experts' with all user accounts in the Contact Selector.


 To do this use the following formula:


In the second activity (Save experts) add a SharePoint List Items event. Configure this event to save the Data Field Experts to the SharePoint Experts column.


As you probably have noticed, the first activity loops through all InfoPath AccountId nodes and appends them to the Experts data field. The second activity just stores the value of this data field in the SharePoint metadata column. Easy as that!

Welkom

Welkom op mijn blog! Ik zal hier regelmatig berichten posten over zaken die ik tijdens mijn werk als SharePoint consultant tegenkom in de praktijk. De problemen en andere interessante dingen die ik tegenkom beschrijf ik zoveel mogelijk op deze blog.