【问题标题】:Cannot set multi-select option field when creating record in Dynamics 365 XRM Web API在 Dynamics 365 XRM Web API 中创建记录时无法设置多选选项字段
【发布时间】:2019-12-23 21:13:18
【问题描述】:

我正在尝试使用 Dynamics 365 Web API 创建记录。试图设置的字段是一个多选选项,应该采用整数数组。传入的值是一个整数数组(第二张截图),但我收到以下错误:

从 JSON 阅读器读取时发现意外的“StartArray”节点。需要一个“PrimitiveValue”节点。?

以下是正在使用的代码,用于识别导致问题的行。

var data = {
            "title": "sample title",
            "new_f1": f1_value,
            "new_meetingdate": meeting_date,
            "new_trainingmodules": training_modules, // Error on this line
            "new_annualnoticedate": annual_notices,

        }  

        Xrm.WebApi.createRecord("incident", data).then(
            function success(result) {
                alert("Case record created.");
            },
            function (error) {
                alert("error.message);
                // handle error conditions
            }
        );

【问题讨论】:

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


    【解决方案1】:

    您无需将多选选项集属性作为数组发送到有效负载中,只需将其作为逗号分隔的字符串值发送即可。

    var training_modules = "100000001, 100000002";
    .
    .
    .
    
    "new_trainingmodules": training_modules,
    

    Reference

    设置多选选项列表值
    使用 Web API,您可以通过传递包含逗号分隔的数字值的字符串来设置值,如下例所示:

    请求

    POST [organization uri]/api/data/v9.0/contacts HTTP/1.1
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    
    {
        "@odata.type": "Microsoft.Dynamics.CRM.contact",
        "firstname": "Wayne",
        "lastname": "Yarborough",
        "sample_outdooractivities": "1, 9"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多