在 Dynamics 365 XRM Web API 中创建记录时无法设置多 select 选项字段

Cannot set multi-select option field when creating record in Dynamics 365 XRM Web API

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

An unexpected 'StartArray' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected.?

下面是正在使用的代码,确定引起问题的行。

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

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

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

"new_trainingmodules": training_modules,

Reference

Setting multi-select picklist values
With the Web API, you set the values by passing a string containing comma separated number values as shown in the following example:

Request

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"
}