我正在尝试使用JavaScript在CRM中创建解决方案。 我的代码是一个网络资源,可通过“ Ribbon Workbench 2016”创建的功能区获得。这些东西很好用,但是当我尝试将从用户(从表单)获得的数据传递给CRM时,标题中会出现错误。
起初,我认为问题在于guid全部为小写,因此我将其转换为大写。没有改变。 然后,我尝试使用发布者的友好名称代替guid。 没有改变。 最后,我很沮丧,所以我使用了一个空字符串,错误从标题中的错误更改为“ linkPath应该有2个段”。猜猜这是一个进步...但是仍然不知道真正的错误可能是什么。
我在做什么错?将解决方案视为实体,然后以这种方式创建它是否正确?有没有更好的办法?
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));
答案 0 :(得分:1)
在Webapi查询下面,我尝试创建solutiona,它确实对我有效。
没什么好照顾的
照顾以上这些确实为我提供了解决方案。
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));