CallMeV 2020-06-14
var clientURL = Xrm.Page.context.getClientUrl(); var req = new XMLHttpRequest() req.open("GET", encodeURI(clientURL + "/api/data/v8.0/systemusers(4C6A6247-43A9-E511-80CF-000D3A806074)/Microsoft.Dynamics.CRM.RetrieveAllChildUsersSystemUser()?$select=fullname"), true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.onreadystatechange = function () { if (this.readyState == 4 /* complete */) { req.onreadystatechange = null; if (this.status == 200) { var responseJSON = JSON.parse(this.responseText); var popstr = ""; if (responseJSON.value != null && responseJSON.value.length >= 1) { for (var i = 0; i < responseJSON.value.length; i++) { popstr += responseJSON.value[i].fullname + ";"; } } Xrm.Utility.alertDialog("这个人下属(含直接下属和非直接下属)包括:" + popstr); } else { var error = JSON.parse(this.response).error; Xrm.Utility.alertDialog("调用函数出错." + error.message); } } }; req.send();
var clientURL = Xrm.Page.context.getClientUrl(); var req = new XMLHttpRequest() req.open("GET", encodeURI(clientURL + "/api/data/v8.0/WhoAmI()"), true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.onreadystatechange = function () { if (this.readyState == 4 /* complete */) { req.onreadystatechange = null; if (this.status == 200) { var responseJSON = JSON.parse(this.responseText); Xrm.Utility.alertDialog("当前用户的ID是:" + responseJSON.UserId + ";所属业务部门ID是" + responseJSON.BusinessUnitId); } else { var error = JSON.parse(this.response).error; Xrm.Utility.alertDialog("调用函数出错." + error.message); } } }; req.send();