Home > SharePoint, SharePoint 2010 > SharePoint 2010: Display SharePoint Groups in an InfoPath Form Drop-Down List Box

SharePoint 2010: Display SharePoint Groups in an InfoPath Form Drop-Down List Box

This post shows the process for making a Drop-Down List Box in an InfoPath form display the SharePoint Groups that exist in the site.

For this example, create a Forms Library which uses InfoPath Forms in your SharePoint site, and edit the new form template in InfoPath Designer.  This form contains a Repeating Table with a Drop-Down List Box which should display a list of SharePoint Groups that are in the site.

This simple form looks like the following:

The Initial InfoPath Form with an empty Drop-Down List Box

The Assigned Group Drop-Down List Box needs to contain the SharePoint Groups, and these will be loaded dynamically rather than added at design-time. To achieve this involves setting up a Data Connection to the GetGroupCollectionFromWeb web method in the User Group web service, and linking this to the Drop-Down List Box.

For the purposes of this example, we will create the Data Connection from within the InfoPath Designer, so click on Data Connections in the Data tab of the ribbon:

The Data Ribbon showing the Data Connections button

When the Data Connections dialog appears, click Add to add a new connection:

Data Connections Dialog

You will be asked for the source of your data. Choose “SOAP Web service”:

Data Connection Wizard 1

Enter the URL to the web service relative to your site, e.g. http://<site>/_vti_bin/UserGroup.asmx?WSDL

Data Connection Wizard 2

Choose the web service method, in this case GetGroupCollectionFromWeb:

Data Connection Wizard 3

Choose whether you want to store a copy of the data in the form template, in this case we won’t:

Data Connection Wizard 4

Enter the name for this data connection, for now use the default called GetGroupCollectionFromWeb. For simplicity of this example, leave the checkbox selected to “Automatically retrieve data when the form is opened”:

Data Connection Wizard 5

After finishing the data connection wizard, you will see the new data connection appear in the Data Connections dialog:

Data Connections Dialog with the new data connection

While this is sufficient for many web service methods, unfortunately this web service method will not work properly as a data connection without some manipulation of the schema file associated with it as part of the form. This is because the schema does not define the full set of nodes that are returned in the web service response. I found this tip by ‘saranlak’ in the SharePoint Creativity Blog.

Fix this involves exporting the InfoPath Form, manipulating an XSD schema file, then opening the InfoPath Form in InfoPath Designer again then carrying on where we left off.

To export the form, go to the File menu, click on Publish and choose “Export Source Files”:

Export Source Files

Then pick a folder on the disk where the exported files will be placed, run the export, then close InfoPath.

The contents of the folder will be similar to the following, although the numbering on the XSD schema files may differ slightly.

Exported Source Files

Open the middle XSD schema file, GetGroupCollectionFromWeb1.xsd in this case, in a text editor such as Notepad, and look for a line near to the top of the file containing the following statement:

<s:import namespace="http://www.w3.org/2001/XMLSchema"></s:import>

If you cannot find this line, look in the other XSD files until you find it.

Immediately below this line, paste the following block which defines all of the elements and attributes for the GetGroupCollectionFromWebType complex type:

<s:complexType name="GetGroupCollectionFromWebType">
		<s:element minOccurs="0" maxOccurs="1" name="Groups">
					<s:element maxOccurs="unbounded" name="Group">
							<s:attribute name="ID" type="s:unsignedShort"></s:attribute>
							<s:attribute name="Name" type="s:string"></s:attribute>
							<s:attribute name="Description" type="s:string"></s:attribute>
							<s:attribute name="OwnerID" type="s:unsignedByte"></s:attribute>
							<s:attribute name="OwnerIsUser" type="s:string"></s:attribute>

Then look for the following block further down the file:

<s:element name="GetGroupCollectionFromWeb">

Replace this block with the following. This uses our new complex type defined above instead of an empty complex type, and so providing all the elements and attributes that we need to use this as a data connection:

<s:element name="GetGroupCollectionFromWeb" type="tns:GetGroupCollectionFromWebType"/>

Save the updated XSD schema file and close it.

Open the manifest.xsf file in InfoPath Designer, and get the properties of the Drop-Down List Box. Select ‘Get choices from an external data source’ then you should see the new data source already selected in the Data source control as follows, or if you have multiple data connections, choose the new data connection:

Selecting the data source

Now bind the Drop-Down List Box to the Name returned from the web service. To do this, click on the button next to the Entries text box then navigate down the tree and select the ‘Group’ node and press OK:

Selecting the Group node

Do similar for the Value and Display name text boxes, but instead choosing ‘:Name’ for both, resulting in the following values selected:

Entries: /dfs:myFields/dfs:dataFields/tns:GetGroupCollectionFromWebResponse/tns:GetGroupCollectionFromWebResult/tns:GetGroupCollectionFromWeb/tns:Groups/tns:Group

Value: @Name

Display name: @Name

Confirm that the Drop-Down List Box Properties now looks follows then press OK:

Drop-Down List Box properties completed

The Drop-Down List Box is now fully setup, so you can carry on editing your form, or to try this out, publish the form back into SharePoint and test it. To publish it, go to the File menu, click on Publish and choose Quick Publish, which will publish the form template back to SharePoint where it originated.

Quick Publish the form back to SharePoint

Now when you add a new item in the Forms Library, the Assigned Group Drop-Down List Box is automatically populated with the SharePoint Groups in the site:

The Final InfoPath Form with the SharePoint Groups displayed in the Drop-Down List Box

  1. jordan
    August 13, 2013 at 13:48

    The groups are only displaying in the manifest file and not the original infopath form I created. It even asks me if I want to connect to the manifest file when I preview the form but there is nothing in the dropdown list. Any Ideas? Thanks.

  2. DDS
    May 14, 2015 at 23:04

    What about users inside a specific group… Following your guide I was able to get the groups but not the users inside… Any help appreciated thanks!

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: