是否可以使用预定义的ID重新创建实体记录? 这个问题的目的是弄清楚如何使用您提供的ID创建实体记录。
例如,当我删除ID为'00 -00-02'的帐户记录时,MS Dynamics CRM中不再存在该记录。因此,现在我想使用具有旧ID('00 -00-02')的REST API重新创建此帐户记录。 有人可以建议我怎么做(或者不可能)吗?
答案 0 :(得分:3)
D365允许您设置实体的主键Guid。通常,在将数据从一个D365组织迁移到另一个D365组织时,我们会遍历ID。
这里是通过Web API在新帐户上设置accountId的示例。 (在Jason Lattimer's CRMRESTBuilder中创建):
var entity = {};
entity.accountid = "008A5AD9-59B7-43BB-BA41-BA59CB5B4769";
entity.name = "Acme Inc.";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/accounts", true);
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.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
答案 1 :(得分:2)
这是相同代码的OrganizationService版本:
RicherIndicator