As I'm putting the finishing touches on my first commercial CRM Utility, I found the need to obtain a list of CRM Queues so that the user can select one from a combo box, like this:
When working with queues, you need to know two things:
1) The Queue Name ( for the user to see ).
2) The Queue ID ( for the CRM system to reference ).
Both of which can be returned by performing a query against the CRM web service.
The following .NET method will return just such a list:
1: private ArrayList GetQueueNames(CrmService myCRMService)
2: {
3: string fetchString =
4: "<fetch version=\"1.0\" "+
5: "output-format=\"xml-platform\" "+
6: "mapping=\"logical\" distinct=\"false\">" +
7: "<entity name=\"queue\">"+
8: "<attribute name=\"name\"/>"+
9: "<attribute name=\"emailaddress\"/>"+
10: "<attribute name=\"businessunitid\"/>"+
11: "<attribute name=\"queueid\"/>"+
12: "<order attribute=\"name\" descending=\"false\"/>"+
13: "<filter type=\"and\">"+
14: "<condition attribute=\"name\" operator=\"not-null\"/>"+
15: "</filter></entity></fetch>";
16:
17: XmlDocument xmlDoc = new XmlDocument();
18: xmlDoc.LoadXml(myCRMService.Fetch(fetchString));
19: XmlNode node = xmlDoc.SelectSingleNode("resultset");
20:
21: ArrayList queueList = new ArrayList();
22: string n1 = string.Empty;
23: string n2 = string.Empty;
24:
25: foreach (XmlNode n in node.ChildNodes)
26: {
27: n1 = n.SelectSingleNode("name").InnerText.ToString();
28: n2 = n.SelectSingleNode("queueid").InnerText.ToString();
29: queueList.Add(new ItemData(n2, n1));
30: }
31:
32: return queueList;
33: }
I created the FetchXML query by following Ronald Lemmen's article on pulling it from the Advanced Find query, which looked like this:
Populating the Combo Box
In order to use the data within a combo box, I had to create a data structure to hold the data. Add this class to your application:
1: public class ItemData
2: {
3:
4: private string m_Value;
5: private string m_Description;
6:
7: public object Value
8: {
9: get { return m_Value; }
10: }
11:
12: public string Description
13: {
14: get { return m_Description; }
15: }
16:
17: public ItemData(string NewValue, string NewDescription)
18: {
19: m_Value = NewValue;
20: m_Description = NewDescription;
21: }
22:
23: public override string ToString()
24: {
25: return m_Description;
26: }
27:
28: }
and use this code to actually populate your combo box:
1:
2: ArrayList queueList = GetQueueNames(myCRMService);
3:
4: if (queueList.Count > 0)
5: {
6: cboQueues.DataSource = queueList;
7: cboQueues.DisplayMember = "Description";
8: cboQueues.ValueMember = "Value";
9:
10: }
I think the same code will work to fill a list box, but I haven't tested it.
Leave a reply