Introduction
Ever wondered how to retrieve the User list from Microsoft CRM 3.0? Well, this tutorial will guide you step by step.
Background
I needed to get a list of all users in a CRM 3.0 system for a custom application, so I decided to utilize the Fetch feature of the Microsoft CRM 3.0 Web Service.
Using the code
Use this XML data to "fetch" the CRM users list:
<fetch mapping='logical'>
<entity name='systemuser'>
<all-attributes/>
</entity>
</fetch>
The next part is to send this request and have the CRM return the result set.
- Load the result set into an
XmlDocument object.
- Use the
SelectNodes method to get the result set.
CRM will return the actual data in this format "resultset/result", it is the "result" table that holds the needed data.
- Iterate through the returned
XmlNodeList and do what you need to do with the data.
In the following example, I am building a drop down list:
string result = service.Fetch(fetchxml);
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(result);
XmlNodeList userList = xdoc.SelectNodes("resultset/result");
foreach(XmlNode n in userList)
{
ListItem itm = new ListItem();
itm.Text = n["fullname"].InnerText;
itm.Value = n["systemuserid"].InnerText;
ddlUserList.Items.Add(itm);
}