Dynamics crm 如何从表单创建注释?
我需要把表格上的文字发送到流通的便条上。我做错了什么Dynamics crm 如何从表单创建注释?,dynamics-crm,odata,microsoft-dynamics,dynamics-crm-webapi,Dynamics Crm,Odata,Microsoft Dynamics,Dynamics Crm Webapi,我需要把表格上的文字发送到流通的便条上。我做错了什么 我需要请添加更多详细信息您可能需要在下面的行中添加倒逗号 var note = Object(); note["notetext"] = "test"; note["subject"] = "Закрытие обращения"; note["incidentid@odata.bind"] = `/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)`; $.ajax( { t
我需要请添加更多详细信息您可能需要在下面的行中添加倒逗号
var note = Object();
note["notetext"] = "test";
note["subject"] = "Закрытие обращения";
note["incidentid@odata.bind"] = `/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)`;
$.ajax( {
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: 'json',
url: 'https://crmw.test.ru/testdb/api/data/v8.2/annotations',
async: true,
data: JSON.stringify( note ),
beforeSend: function ( XMLHttpRequest )
{
XMLHttpRequest.setRequestHeader( "Accept", "application/json" );
XMLHttpRequest.setRequestHeader( "OData-MaxVersion", "4.0" );
XMLHttpRequest.setRequestHeader( "OData-Version", "4.0" );
},
success: function ( data, textStatus, XmlHttpRequest )
{
let result = data;
alert( "Record created successfully" );
},
error: function ( XmlHttpRequest, textStatus, errorThrown )
{
alert("ошибка"+ XmlHttpRequest + textStatus + errorThrown);
}
} );
下面是我尝试过并为我工作得很好的代码
note["incidentid@odata.bind"] ="/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)";
问题在于单值导航属性,它应该是
objectid_incident@odata.bind
而不是incidentid@odata.bind
换行
var entity = {};
entity.subject = "Test from WEbapi 3";
entity.filename = "File Name 123";
entity["objectid_incident@odata.bind"] = "/incidents(C86A8897-D94F-E911-A82F-000D3A385A1C)";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/annotations", 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));
如下图所示,它将起作用
您可以使用CRM REST Builder构建和测试查询,而不存在语法问题
note["incidentid@odata.bind"] = `/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)`;
note["objectid_incident@odata.bind"] = "/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)";