"Resource not found for the segment *publisherguid*" 在 XMLHTTP 查询中创建 CRM 中的解决方案
"Resource not found for the segment *publisherguid*" in XMLHTTP query to create solution in the CRM
我正在尝试使用 javascript 在 CRM 中创建解决方案。
我的代码是一个网络资源,我通过使用 "Ribbon Workbench 2016" 创建的功能区获得它。这些东西工作得很好,但是当我尝试将从用户(从表单)获得的数据传递给 CRM 时,我在标题中收到错误。
一开始以为是guid全是小写的问题,所以转成大写。没有改变。
然后我尝试使用发布者的友好名称而不是 guid。
没有改变。
最后,我很沮丧,所以我使用了一个空字符串,错误从标题中的那个变成了“linkPath should have 2 segments”。猜猜这是一个进步......但仍然不知道真正的错误可能是什么。
我做错了什么?将解决方案视为一个实体并以这种方式创建它是否正确?有没有更好的办法?
PS:查询是使用 CRM Rest Builder 生成的
var entity = {};
entity.friendlyname = $("#solutionForm").dxForm("instance").getEditor("Friendly name").option("value");
entity.uniquename = $("#solutionForm").dxForm("instance").getEditor("Unique name").option("value");
entity.version = $("#solutionForm").dxForm("instance").getEditor("Version").option("value");
entity["publisherid@odata.bind"] = keyValueContainerForPublishers[($("#solutionForm").dxForm("instance").getEditor("Publisher").option("value"))]; //contains guid of selected publisher
entity["configurationpageid@odata.bind"] = "";
entity.description = $("#solutionForm").dxForm("instance").getEditor("Description").option("value");
entity.solutionid = newGuid(); //create unique guid
entity.solutionpackageversion = null;
entity.solutiontype = 0;
var req = new XMLHttpRequest();
req.open("POST", window.parent.opener.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/solutions", 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 {
window.parent.opener.Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
好的,在我尝试创建解决方案的 Webapi 查询下面,它确实对我有效。
需要注意的几点
- 版本应该是 1.0 或 2.0 左右。只有 1 或 2 行不通
- 发布者,如果你比较你的代码和我的代码,它应该是 "publishers" 而不是 "publisher"
- SolutionID你不用说它会自动创建
- 我暂时没有使用 configuraitonPageID 和 solutionPackageVersion。
照顾好以上事情确实为我创造了一个解决方案。
var entity = {};
entity.friendlyname = "Test solution from WebAPI";
entity.uniquename = "TestSolutionFromWebAPI";
entity.version = "1.0";
entity["publisherid@odata.bind"] = "/publishers(6007BA03-EE7A-4CA1-A146-7EB0044E504F)";
entity.description = "This is test solution form webapi";
entity.solutiontype = 0;
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/solutions", 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.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));
我正在尝试使用 javascript 在 CRM 中创建解决方案。 我的代码是一个网络资源,我通过使用 "Ribbon Workbench 2016" 创建的功能区获得它。这些东西工作得很好,但是当我尝试将从用户(从表单)获得的数据传递给 CRM 时,我在标题中收到错误。
一开始以为是guid全是小写的问题,所以转成大写。没有改变。 然后我尝试使用发布者的友好名称而不是 guid。 没有改变。 最后,我很沮丧,所以我使用了一个空字符串,错误从标题中的那个变成了“linkPath should have 2 segments”。猜猜这是一个进步......但仍然不知道真正的错误可能是什么。
我做错了什么?将解决方案视为一个实体并以这种方式创建它是否正确?有没有更好的办法?
PS:查询是使用 CRM Rest Builder 生成的
var entity = {};
entity.friendlyname = $("#solutionForm").dxForm("instance").getEditor("Friendly name").option("value");
entity.uniquename = $("#solutionForm").dxForm("instance").getEditor("Unique name").option("value");
entity.version = $("#solutionForm").dxForm("instance").getEditor("Version").option("value");
entity["publisherid@odata.bind"] = keyValueContainerForPublishers[($("#solutionForm").dxForm("instance").getEditor("Publisher").option("value"))]; //contains guid of selected publisher
entity["configurationpageid@odata.bind"] = "";
entity.description = $("#solutionForm").dxForm("instance").getEditor("Description").option("value");
entity.solutionid = newGuid(); //create unique guid
entity.solutionpackageversion = null;
entity.solutiontype = 0;
var req = new XMLHttpRequest();
req.open("POST", window.parent.opener.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/solutions", 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 {
window.parent.opener.Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
好的,在我尝试创建解决方案的 Webapi 查询下面,它确实对我有效。
需要注意的几点
- 版本应该是 1.0 或 2.0 左右。只有 1 或 2 行不通
- 发布者,如果你比较你的代码和我的代码,它应该是 "publishers" 而不是 "publisher"
- SolutionID你不用说它会自动创建
- 我暂时没有使用 configuraitonPageID 和 solutionPackageVersion。
照顾好以上事情确实为我创造了一个解决方案。
var entity = {};
entity.friendlyname = "Test solution from WebAPI";
entity.uniquename = "TestSolutionFromWebAPI";
entity.version = "1.0";
entity["publisherid@odata.bind"] = "/publishers(6007BA03-EE7A-4CA1-A146-7EB0044E504F)";
entity.description = "This is test solution form webapi";
entity.solutiontype = 0;
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/solutions", 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.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));