【问题标题】:How to create the annotation from the form?如何从表单创建注释?
【发布时间】:2019-04-24 11:02:13
【问题描述】:
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);
    }
} );

我需要将表单中的文本发送到流通中的便笺。我做错了什么?

我需要,请添加更多详细信息

【问题讨论】:

    标签: dynamics-crm odata microsoft-dynamics dynamics-crm-webapi


    【解决方案1】:

    问题在于单值导航属性,它应该是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)";
    

    Reference

    您可以使用 CRM REST Builder 构建和测试查询,而不会出现语法问题。

    【讨论】:

      【解决方案2】:

      您可能必须在下面的行中添加引号

      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));
      

      【讨论】:

        猜你喜欢
        • 2013-03-10
        • 2011-10-18
        • 2021-12-30
        • 2011-12-20
        • 2016-10-31
        • 1970-01-01
        • 2012-11-04
        • 1970-01-01
        • 2011-10-09
        相关资源
        最近更新 更多