In this post I will show a method to display Group membership of a user without writing any code behind in InfoPath form. This method will take advantage of the usergroup.asmx web service. We will try to get data from “GetGroupCollectionFromUser”.
Creating a Secondary Data Connection to UserGroup.asmx web service
1) Create a new Data Connection from “Tools” menu:
2) Create “Receive Data” connection:
3) Select Web Service as source of data:
4) Give service address (it should be http://youserver/_vit_bin/usergroup.asmx):
you can check in the browser first:
5) Select GetGroupCollectionFromUser web method:
6) Give a real username otherwise this will not allow you create the connection:
You can leave next step blank as we will specify the input parameter from a input field:
7) We will not store a copy of data for this example but you can chose to do that:
8) I will give this connection a friendly name and will not try to automatically get data on opening form as I will specify the input parameter once form is loaded:
Saving Form as Source File
Once you have followed the above steps, you can choose data source in the tab view and see the fields available to you in this connection:
As you can see above return fields in the connection do not reflect the fields that are returned by the web service. To correct these fields we will have to modify the schema file. To modify the schema first same the form as “Source Files”:
Once you have done that you can browse to the folder and see the following files in uncompressed form:
File of our interest is GetGroups1.xsd.
Correcting the xsd for the Return Fields
In the code below you will see that GetGroupCollectionFromUser method return fields are not same the fields specified by the method in MSDN site: http://msdn.microsoft.com/en-us/library/ms772552.aspx.
<Group ID="3" Name="Group1" Description="Description" OwnerID="1"
<Group ID="15" Name="Group2" Description="Description"
OwnerID="12" OwnerIsUser="True" />
<Group ID="16" Name="Group3" Description="Description"
OwnerID="7" OwnerIsUser="False" />
In order to correct the fields we will modify the GetGroups1.xsd file as following:
1) Add new “ComplexType” definition to the GetGroups1.xsd:
Just below this line:
Add this section:
After Saving the changes
Once you save the GetGroups1.xsd file right click Manifest.xsf file and chose design. Now is you choose data source you will able to see the new fields:
I drag-dropped the “Group” repeating group as “repeating table” and a text-field to input the username.
Note: You have to provide fully qualified name domain name (domain\username) in order to get the group data.