Tuesday 14 May 2013

InfoPath Dropdown Site Groups

To get started open up InfoPath, create a Blank Form, add one drop down list and a button; below is more or less what it should look like.

In the fields menu on the right rename myFields to “Association Fields” and field1 to “SelectedGroup”. You can do this by right clicking on each of the default names, and selecting properties. Give the field a new name and hit save. If the Fields pane is not available go to the Data menu and click the show fields button.

Next let`s set up our SOAP service, to pull this off go to your Data Menu, hit the From Web Service button and select From SOAP Web Service.

Next enter in the url of your SOAP service http://yoursite:portNumber/_vti_bin/UserGroup.asmx?WSDL

On a side note if you want to view all the web services available go to
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI or check out
SharePoint Foundation 2010 Web Services.

Select the SOAP function you want in our case it`s GetGroupCollectionFromSite

Leave it unchecked, if you`re curious read it.

Leave the default name.

Next you`re going to have to publish the source files, hit the File menu, click the publish tab and click the export source files button

Put your source files somewhere where you`ll remember.

once saved Make sure to close InfopPath and navigate to the file folder where you saved the source files.

This next part is the magic, it was shown to me by a consultant that I worked with, not sure where she got it from but wow I`d have never come up with this, so kudos to her.

Your Main concern is going to be with the GetGroupCollectionFromSite1.xsd file. Open that sucker up in some sort of XML viewing software.
Now the third line from the top should be

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

Directly after it add the following XML

<s:complexType name="GetGroupsFromSiteType">
    <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>

Keep in mind that the ID, Description, OwnerID, OwnerIsUser fields are optional for this example, you don`t use them in the form, but hey you might. Next search for the text "GetGroupCollectionFromSite" it should be around line 340, just before or right after and look like:

<s:element name="GetGroupCollectionFromSite">

now replace it with

<s:element name="GetGroupCollectionFromSite" type="tns:GetGroupsFromSiteType"/>

save the file up and close it

next open up InfoPath once again and open the source files manifest file through Infopath, don`t just double click on the file.

After you`ve opened up your source files, right click on the drop down list-box and hit the properties

Next you should see the Drop-Down List Box Properties Form, under List Box Choices pick the third option “Get choices from an external data source”

Click the entries button and select the group

do the same for the value and display name fields, make sure to pick the Name property

next you may have some permission issues, if that`s the case then set your form security to full trust. It`s your form so I don`t see why that would be a problem.

You should be able to hit the preview button now and your drop down list should be populated with all of the site groups.

There`s still the matter of setting up the submit button, but that`s fairly trivial and for my next post cause this one is far too long in my opinion.