以下为效果图:
修改AdvancedFind目录下AdvFind.aspx文件。
1、在"<cui:Button ID="btnRun" OnClick="ExecuteQuery()" runat="server"></cui:Button>"上方增加“<cui:Button ID="btnbusiness" OnClick="getbusiness()" runat="server" Text="获取该部门下的所有客户"></cui:Button>”。
2、增加js代码:
Code
1 <script>
2 function getbusinessitem(rootid) {
3 var xml = "" +
4 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
5 "<soap:Envelope 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/">" +
6 " <soap:Body>" +
7 " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query/" xsi:type=\"q1:QueryExpression\" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices/">" +
8 " <q1:EntityName>businessunit</q1:EntityName>" +
9 " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
10 " <q1:Attributes>" +
11 " <q1:Attribute>businessunitid</q1:Attribute>" +
12 " </q1:Attributes>" +
13 " </q1:ColumnSet>" +
14 " <q1:Distinct>false</q1:Distinct>" +
15 " <q1:Criteria>" +
16 " <q1:FilterOperator>And</q1:FilterOperator>" +
17 " <q1:Conditions>" +
18 " <q1:Condition>" +
19 " <q1:AttributeName>parentbusinessunitid</q1:AttributeName>" +
20 " <q1:Operator>Equal</q1:Operator>" +
21 " <q1:Values>" +
22 " <q1:Value xmlns:q2=\"http://microsoft.com/wsdl/types//" xsi:type=\"q2:guid\">"+rootid+"</q1:Value>" +
23 " </q1:Values>" +
24 " </q1:Condition>" +
25 " </q1:Conditions>" +
26 " </q1:Criteria>" +
27 " </query>" +
28 " </soap:Body>" +
29 "</soap:Envelope>" +
30 "";
31
32 var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
33
34 xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
35 xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple");
36 xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
37 xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
38 xmlHttpRequest.send(xml);
39 var resultXml = xmlHttpRequest.responseXML;
40
41 return resultXml;
42 }
43 var businessitem = new Array();
44 function setbusinessitem(resultXml) {
45 var doc = new ActiveXObject("Msxml2.DOMDocument");
46 doc.load(resultXml);
47 var bu = doc.getElementsByTagName("BusinessEntity");
48 for (var i = 0; i < bu.length; i++) {
49 var childs = bu[i].childNodes;
50 for (var j = 0; j < childs.length; j++) {
51 businessitem.push(childs[j].firstChild.nodeValue);
52 setbusinessitem(getbusinessitem(childs[j].firstChild.nodeValue));
53 }
54 }
55 }
56 function getbusiness() {
57 var fetchxml = advFind.FetchXml;
58 if (fetchxml == null)
59 return;
60 if (fetchxml.indexOf("<condition attribute=\"businessunitid\"") == -1) {
61 alert("业务部门字段缺少值,请正确选择!");
62 return;
63 }
64
65 var doc = new ActiveXObject("Microsoft.XMLDOM");
66 doc.async = "false";
67 doc.loadXML(fetchxml);
68 var buid = doc.selectSingleNode("//condition[@attribute='businessunitid']");
69 var buidcache = buid.parentNode;
70
71 var getrootbuid = buid.childNodes;
72 if (getrootbuid.length>0) {
73 alert("只允许选择一个部门!");
74 return;
75 }
76
77 getrootbuid = buid.getAttributeNode("value").nodeValue;
78 buid.parentNode.removeChild(buid);
79
80 var doc1 = new ActiveXObject("Microsoft.XMLDOM");
81 var newbuid = doc1.createNode(1,"condition","");
82 var r = doc1.createAttribute("attribute");
83 r.value = "businessunitid";
84 newbuid.setAttributeNode(r);
85 r = doc1.createAttribute("operator");
86 r.value = "in";
87 newbuid.setAttributeNode(r);
88
89
90 businessitem = new Array();
91 businessitem.push(getrootbuid);
92 setbusinessitem(getbusinessitem(getrootbuid));
93
94 if (businessitem.length < 0)
95 return;
96 for (var i = 0; i < businessitem.length; i++) {
97 var n = doc1.createNode(1, "value", "");
98 r = doc1.createAttribute("uitype");
99 r.value = "businessunit";
100 n.setAttributeNode(r);
101 r = doc1.createAttribute("uiname");
102 r.value = "1212";
103 n.setAttributeNode(r);
104 n.appendChild(doc1.createTextNode(businessitem[i]));
105 newbuid.appendChild(n);
106 }
107 buidcache.appendChild(newbuid);
108
109 var sFetchXml = doc.xml;
110 if (sFetchXml == null) {
111 return;
112 }
113
114
115 with (resultRender) {
116 FetchXml.value = sFetchXml;
117 LayoutXml.value = advFind.LayoutXml;
118 EntityName.value = advFind.EntityName;
119 DefaultAdvFindViewId.value = advFind.DefaultAdvancedFindViewId;
120 ViewId.value = advFind.QueryId;
121 ViewType.value = advFind.QueryObjectType;
122
123
124 if (_oXmlDom.loadXML(sFetchXml)) {
125 var oOrderNode = _oXmlDom.selectSingleNode("/fetch/entity/order");
126 if (oOrderNode != null) {
127 var s = oOrderNode.getAttribute("attribute");
128 SortCol.value = s == null ? "" : s;
129
130 s = oOrderNode.getAttribute("descending");
131 SortDescend.value = s == null ? false : s;
132 }
133 }
134 }
135
136
137 resultFrame.document.body.innerHTML = "<table height='100%' width='100%' style='cursor:wait'><tr><td valign='middle' align='center'><img alt='' src='/_imgs/AdvFind/progress.gif'/><br>" + LOCID_AF_EXECUTINGSEARCH + "</td></tr></table>";
138 switchTo("SEARCH");
139
140 window.setTimeout("resultRender.submit()", 10);
141 }
142 </script>
143
144
1 <script>
2 function getbusinessitem(rootid) {
3 var xml = "" +
4 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
5 "<soap:Envelope 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/">" +
6 " <soap:Body>" +
7 " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query/" xsi:type=\"q1:QueryExpression\" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices/">" +
8 " <q1:EntityName>businessunit</q1:EntityName>" +
9 " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
10 " <q1:Attributes>" +
11 " <q1:Attribute>businessunitid</q1:Attribute>" +
12 " </q1:Attributes>" +
13 " </q1:ColumnSet>" +
14 " <q1:Distinct>false</q1:Distinct>" +
15 " <q1:Criteria>" +
16 " <q1:FilterOperator>And</q1:FilterOperator>" +
17 " <q1:Conditions>" +
18 " <q1:Condition>" +
19 " <q1:AttributeName>parentbusinessunitid</q1:AttributeName>" +
20 " <q1:Operator>Equal</q1:Operator>" +
21 " <q1:Values>" +
22 " <q1:Value xmlns:q2=\"http://microsoft.com/wsdl/types//" xsi:type=\"q2:guid\">"+rootid+"</q1:Value>" +
23 " </q1:Values>" +
24 " </q1:Condition>" +
25 " </q1:Conditions>" +
26 " </q1:Criteria>" +
27 " </query>" +
28 " </soap:Body>" +
29 "</soap:Envelope>" +
30 "";
31
32 var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
33
34 xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
35 xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple");
36 xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
37 xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
38 xmlHttpRequest.send(xml);
39 var resultXml = xmlHttpRequest.responseXML;
40
41 return resultXml;
42 }
43 var businessitem = new Array();
44 function setbusinessitem(resultXml) {
45 var doc = new ActiveXObject("Msxml2.DOMDocument");
46 doc.load(resultXml);
47 var bu = doc.getElementsByTagName("BusinessEntity");
48 for (var i = 0; i < bu.length; i++) {
49 var childs = bu[i].childNodes;
50 for (var j = 0; j < childs.length; j++) {
51 businessitem.push(childs[j].firstChild.nodeValue);
52 setbusinessitem(getbusinessitem(childs[j].firstChild.nodeValue));
53 }
54 }
55 }
56 function getbusiness() {
57 var fetchxml = advFind.FetchXml;
58 if (fetchxml == null)
59 return;
60 if (fetchxml.indexOf("<condition attribute=\"businessunitid\"") == -1) {
61 alert("业务部门字段缺少值,请正确选择!");
62 return;
63 }
64
65 var doc = new ActiveXObject("Microsoft.XMLDOM");
66 doc.async = "false";
67 doc.loadXML(fetchxml);
68 var buid = doc.selectSingleNode("//condition[@attribute='businessunitid']");
69 var buidcache = buid.parentNode;
70
71 var getrootbuid = buid.childNodes;
72 if (getrootbuid.length>0) {
73 alert("只允许选择一个部门!");
74 return;
75 }
76
77 getrootbuid = buid.getAttributeNode("value").nodeValue;
78 buid.parentNode.removeChild(buid);
79
80 var doc1 = new ActiveXObject("Microsoft.XMLDOM");
81 var newbuid = doc1.createNode(1,"condition","");
82 var r = doc1.createAttribute("attribute");
83 r.value = "businessunitid";
84 newbuid.setAttributeNode(r);
85 r = doc1.createAttribute("operator");
86 r.value = "in";
87 newbuid.setAttributeNode(r);
88
89
90 businessitem = new Array();
91 businessitem.push(getrootbuid);
92 setbusinessitem(getbusinessitem(getrootbuid));
93
94 if (businessitem.length < 0)
95 return;
96 for (var i = 0; i < businessitem.length; i++) {
97 var n = doc1.createNode(1, "value", "");
98 r = doc1.createAttribute("uitype");
99 r.value = "businessunit";
100 n.setAttributeNode(r);
101 r = doc1.createAttribute("uiname");
102 r.value = "1212";
103 n.setAttributeNode(r);
104 n.appendChild(doc1.createTextNode(businessitem[i]));
105 newbuid.appendChild(n);
106 }
107 buidcache.appendChild(newbuid);
108
109 var sFetchXml = doc.xml;
110 if (sFetchXml == null) {
111 return;
112 }
113
114
115 with (resultRender) {
116 FetchXml.value = sFetchXml;
117 LayoutXml.value = advFind.LayoutXml;
118 EntityName.value = advFind.EntityName;
119 DefaultAdvFindViewId.value = advFind.DefaultAdvancedFindViewId;
120 ViewId.value = advFind.QueryId;
121 ViewType.value = advFind.QueryObjectType;
122
123
124 if (_oXmlDom.loadXML(sFetchXml)) {
125 var oOrderNode = _oXmlDom.selectSingleNode("/fetch/entity/order");
126 if (oOrderNode != null) {
127 var s = oOrderNode.getAttribute("attribute");
128 SortCol.value = s == null ? "" : s;
129
130 s = oOrderNode.getAttribute("descending");
131 SortDescend.value = s == null ? false : s;
132 }
133 }
134 }
135
136
137 resultFrame.document.body.innerHTML = "<table height='100%' width='100%' style='cursor:wait'><tr><td valign='middle' align='center'><img alt='' src='/_imgs/AdvFind/progress.gif'/><br>" + LOCID_AF_EXECUTINGSEARCH + "</td></tr></table>";
138 switchTo("SEARCH");
139
140 window.setTimeout("resultRender.submit()", 10);
141 }
142 </script>
143
144