Get User Collection from a Sharepoint Group
Posted by Jessica Wang on March 25, 2008
I have been working on getting a drop down list in Infopath to be populated with users of a Sharepoint Group. You can’t connect directly to the drop drop list, so you will need to create 2 data sources, 1 to the web service and another xml file with dummy data which will be replace be information from the web service.
1. Create a data connection to the web service using the data connection wizard.
<http://servername/_vti_bin/UserGroup.asmx?WSDL>
Click next and select GetUserCollectionFromGroup
Enter Sample data, which is the name of the group which you wish to get data from.
2. You will need dummy data to be connected to the drop down list first. There are 2 dummy users in the xml, it tells infopath that it is repeating.
DummyData.xml
<?xml version=”1.0″ encoding=”utf-8″ ?> <dfs:myFields xmlns:dfs=”http://schemas.microsoft.com/office/infopath/2003/dataFormSolution” xmlns:s0=”http://schemas.microsoft.com/sharepoint/soap/directory/” xmlns:my=”http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-03-16T06-17-54″ xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <dfs:queryFields> <s0:GetUserCollectionFromGroup> </s0:GetUserCollectionFromGroup> </dfs:queryFields> <dfs:dataFields> <GetUserCollectionFromGroupResponse xmlns=”http://schemas.microsoft.com/sharepoint/soap/directory/”> <GetUserCollectionFromGroupResult> <GetUserCollectionFromGroup> <Users> <User ID=”1″ Sid=”S-1-5-21-3593225548-2099380924-3969701235-500″ Name=”User1″ LoginName=”login1″ Email=”user1@users.com” Notes=”” IsSiteAdmin=”False” IsDomainGroup=”False”/> <User ID=”2″ Sid=”S-1-5-21-3593225548-2099380924-3969701235-1145″ Name=”User2″ LoginName=”login2″ Email=”user2@users.com” Notes=”” IsSiteAdmin=”False” IsDomainGroup=”False”/> </Users> </GetUserCollectionFromGroup> </GetUserCollectionFromGroupResult> </GetUserCollectionFromGroupResponse> </dfs:dataFields></dfs:myFields> |
Save the dummydata.xml and connect it via the Data Connection Wizard as well.
3. Link the drop down list to the dummydata.xml
4. You will need to go to the loading event of the infopath form, which you can get to by going to Tools>Programming>Loading Event
It will open up Visual studio. Within the Loading Event, you will need the following piece of code.
public void FormEvents_Loading(object sender, LoadingEventArgs e) { //Dummy Data //get an XPathNavigator to our webservice method XPathNavigator dutyManagerDummy = this.DataSources[“DutyManagerListDummyData”].CreateNavigator(); //create the XmlNamespaceManager that will allow us to navigate the xml umanager.AddNamespace(“dfs”, http://schemas.microsoft.com/office/infopath/2003/dataFormSolution); umanager.AddNamespace(“tns”, http://schemas.microsoft.com/sharepoint/soap/directory/); //get the node that contains all the users from dummy data //Actual Data //get an XPathNavigator to our webservice method XPathNavigator dutyManager = this.DataSources[“GetUserCollectionFromGroup”].CreateNavigator(); //create the XmlNamespaceManager that will allow us to navigate the xml dmanager.AddNamespace(“dfs”, http://schemas.microsoft.com/office/infopath/2003/dataFormSolution); dmanager.AddNamespace(“tns”, http://schemas.microsoft.com/sharepoint/soap/directory/); //get the node that contains all the users from the call to the web service try{ //replace the dummy information from the information from the web service } catch(NullReferenceException ee){} } |
Run the preview and you should see the actual data instead of the dummy information.
Eric Smith said
Handy post. I happened to find myself with a very similar problem last week. What I really need is a list of domain users in various AD groups. MOSS 2007 can clearly find this information itself but will it make it available as it does its own groups?
Hi Eric,
Sharepoint will allow you to add domain/users from various AD groups into Sharepoint Groups.
However, using the method that I stated, it will just display domain/users and not the list of users in the domain/users
Example:
domain/users
domain/guests
sydney/users
melbourne/admin
Cheers,
Jessica Wang
SEMA said
what if you have multiple domains? is there anyway to bring up all users from all domains?
thanks
Juan Larios said
You should specify that this solution only works with InfoPath 2007. And you also need Microsoft Visual Studio Tools for Applications (VSTA). This is a useless solution for InfoPath 2003. And if you want to stay confined to script instead of code.
but other than that, I really like this post, I will definitely use it if a client has the essentials needed to make this solution work.
Juan
kevin said
an excellant Posting a question though, can you have multiple drop downs on the same pages, i am having errors being able to have more then one on a form
chris said
Hi Jessica,
I have the same problem than Kevin, do you have an idea?
Have a nice day!
Chris
Henry Min said
Hi Jessica,
Is there any way to pass groupname from the form control (value from text box) to populate user list?
Thanks,
Henry
Jessica Wang said
I haven’t done it before, but there is a reply on the msdn blog which seems to be what you are looking for.
“Hi,
I am able to Send a user entered value in the “txtEmailID” text box to the webservice method dynamically & the webservice returns the value of the specific user whose email id is passed on.
Just added a two rule to the button in that order:-
1. Set a field value of the webservice input parameter “searchText = txtEmailId”
2. Query using a data connection (SearchPrincipal)
Finally cleaned up the default value given at the time of dataconnection wizard “Set value” for the parameter “searchText” bcz now I am setting it to the user entred value dynamically.”
DooriaGam said
well.. it’s like I thought!
Meri said
I’m getting an “unspecified error” when trying to add the XML file as a data connection. Has anyone else encountered this and come up with a solution?