如何从表单创建注释?
How to create the annotation from the form?
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)";
下面是我尝试过的代码,效果很好。
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));
问题出在 单值导航 属性,它应该是 objectid_incident@odata.bind
而不是 incidentid@odata.bind
更改此行
note["incidentid@odata.bind"] = `/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)`;
像下面这样,就可以了。 Read more
note["objectid_incident@odata.bind"] = "/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)";
您可以使用 CRM REST Builder 构建和测试查询,而不会出现语法问题。
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)";
下面是我尝试过的代码,效果很好。
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));
问题出在 单值导航 属性,它应该是 objectid_incident@odata.bind
而不是 incidentid@odata.bind
更改此行
note["incidentid@odata.bind"] = `/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)`;
像下面这样,就可以了。 Read more
note["objectid_incident@odata.bind"] = "/incidents(FC8F144E-06E7-E711-80C7-0050569B0E28)";
您可以使用 CRM REST Builder 构建和测试查询,而不会出现语法问题。