dynamics-crm - 使用 Web API 进行用户模拟
问题描述
如何代表其他用户检索记录。
Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name&$top=3").then(
function success(result) {
for (var i = 0; i < result.entities.length; i++) {
console.log(result.entities[i]);
}
// perform additional operations on retrieved records
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
解决方案
我知道我们可以XMLHttpRequest
通过传递MSCRMCallerID
标题来进行模拟。不确定我们能否在Xrm.WebApi
.
这是我的产品代码,在来自 HTML 网络资源的管理员模拟下执行一些更新/分配操作。
var entity = {};
entity["ownerid@odata.bind"] = "/systemusers(" + currentUserId + ")";
var req = new XMLHttpRequest();
req.open("PATCH", parent.Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.1/new_customentity(" + opptyid + ")", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("MSCRMCallerID", "0AFB2F7E-D323-E511-80F0-C4346BAC29F0"); //CRM Admin impersoantion
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success - No Return Data - Do Something
} else {
//Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
更新
传递标头是唯一的方法,Xrm.WebApi
不能接受请求标头。
文档说:
有两种方法可以模拟用户,这两种方法都可以通过传入带有相应用户 ID 的标头来实现。
Preferred:通过将该值与 header 一起传递,根据用户的 Azure Active Directory (AAD) 对象 ID 模拟用户
CallerObjectId
。
Legacy:要根据用户的 systemuserid 模拟用户,您可以利用MSCRMCallerID
相应的 guid 值。
推荐阅读
- c - 如何在 OpenMP 中实现 MPI_MINLOC?
- amazon-web-services - 在我的 EC2 实例上安装 SSM 代理,以便在没有 SSH 或密钥对的情况下安装 Inspector 代理
- javascript - 为 ChartsJs 中的图表添加第二个自定义工具提示
- reactjs - 如何测试我的操作、状态和 UI。我正在使用带有 jest 和测试库的上下文 API?
- xml - 使用 PowerShell 循环遍历 XML 时遇到问题
- json - 如何访问 Apex 中的嵌套 JSON?
- python - Pandas 将逗号分隔的键值输出成表格形式
- datatables - 没有滚动条时处理消息位置的数据表
- javascript - JS - 使用 FileReader 对象时只允许上传一个文件
- html - 如何在移动布局中居中文本?