18 October 2009

InfoPath: Displaying SharePoint Group List Using “GetGroupCollectionFromUser” method

 

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:

 DC-1

2) Create “Receive Data” connection:

DC-2

3) Select Web Service as source of data:

DC-3

4) Give service address (it should be http://youserver/_vit_bin/usergroup.asmx):

DC-4

you can check in the browser first:

DC-5

5) Select GetGroupCollectionFromUser web method:

DC-6

6) Give a real username otherwise this will not allow you create the connection:

DC-7

You can leave next step blank as we will specify the input parameter from a input field: 

DC-8

7) We will not store a copy of data for this example but you can chose to do that:

DC-9

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:

DC-10

 

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:

BeforeFields

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”:

SaveAsSource

Once you have done that you can browse to the folder and see the following files in uncompressed form:

InfoPathFolder  

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.

<s:element name="GetGroupCollectionFromUser">



        <s:complexType>



            <s:sequence>



                <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string"></s:element>



            </s:sequence>



        </s:complexType>



    </s:element>



    <s:element name="GetGroupCollectionFromUserResponse">



        <s:complexType>



            <s:sequence>



                <s:element minOccurs="0" maxOccurs="1" name="GetGroupCollectionFromUserResult">



                    <s:complexType mixed="true">



                        <s:sequence>



                            <s:any></s:any>



                        </s:sequence>



                    </s:complexType>



                </s:element>



            </s:sequence>



        </s:complexType>



    </s:element>




According to the article we should have the schema which reflect following fields:


Return Value


<GetGroupCollectionFromUser xmlns=
"http://schemas.microsoft.com/sharepoint/soap/directory/">
<Groups>
<Group ID="3" Name="Group1" Description="Description" OwnerID="1"
OwnerIsUser="False" />
<Group ID="15" Name="Group2" Description="Description"
OwnerID="12" OwnerIsUser="True" />
<Group ID="16" Name="Group3" Description="Description"
OwnerID="7" OwnerIsUser="False" />
</Groups>
</GetGroupCollectionFromUser>




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:





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




 



Add this section:





<s:complexType name="GetGroupCollectionFromUserType">



   <s:sequence>



     <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string"/>



     <s:element minOccurs="0" maxOccurs="1" name="Groups">



       <s:complexType>



         <s:sequence>



           <s:element maxOccurs="unbounded" name="Group" >



             <s:complexType>



               <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>



             </s:complexType>



           </s:element>



         </s:sequence>



       </s:complexType>



     </s:element>



   </s:sequence>



 </s:complexType>




 



2) Replace:





<s:element name="GetGroupCollectionFromUser">



        <s:complexType>



            <s:sequence>



                <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string"></s:element>



            </s:sequence>



        </s:complexType>



    </s:element>




with:





<!--<s:element name="GetGroupCollectionFromUser">



      <s:complexType>



          <s:sequence>



              <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string"></s:element>



          </s:sequence>



      </s:complexType>



  </s:element>-->



<s:element name="GetGroupCollectionFromUser" type="tns:GetGroupCollectionFromUserType" />








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:



AfterFields



I drag-dropped the “Group” repeating group as “repeating table” and a text-field to input the username.



GroupTable



Note: You have to provide fully qualified name domain name (domain\username) in order to get the group data.

1 comment:

Anonymous said...

It is not working . I tried all the same steps