SharePoint Online 将项目发布到具有元素字段的列表

SharePoint Online posting an item to a list with element field

我有一个包含多个字段的 SharePoint 列表。我通过执行以下操作使用 JavaScript 到 post 到列表:

$.ajax({
    url: "https://my.domain.com/sites/mysite/_api/web/lists/getbytitle('listname')/items",
    type: "POST",
    contentType: "application/json;odata=verbose",
    data: data,//Example WORKING JSON{ '__metadata': { 'type': 'SP.Data.TestListItem' }, 'title': 'Test' },
    headers: {
        "Accept": "application/json;odata=verbose",
        "Authorization": "Bearer " + token
    },
    success: function (data) {
        console.log("Success");
    },
    error: function (data) {
        console.log("Failure");
    }
});

效果非常好。问题是我的一个领域,当我使用 Postman 时是这样的:

<d:Sst_Country_mc m:type="Collection(Edm.String)">
   <d:element>Netherlands</d:element>
</d:Sst_Country_mc>

所以我认为我的 Json 会是这样的:

{
  "__metadata": {
    "type": "SP.Data.SST_x0020_Requests_x0020_StagingListItem"
  },
  "Title": "Andrew Test 4",
  "Sst_Customer_Name_st": "Customer",
  "Sst_Business_Category_sc": "Finance and Insurance",
  "Sst_Country_mc": {
    "element": "Spain"
  },
  "Sst_Actual_Request_mt": "",
  "Sst_E_Model_1_st": "MODEL",
  "Sst_E_Hardware_Qty_1_ni": "1",
  "Sst_Deadline_Validate_d": "01/01/2017",
  "Sst_Office_sc": "B UK"
}

但是失败并出现以下错误:

A collection was found without the 'results' property. In OData, each collection must be represented as a JSON object with a property 'results'.

这与我如何 posting 无关,因为当我删除该字段时,它可以工作,但我需要填充此字段以用于启动项目创建的工作流程。

我的 Json 应该如何格式化以处理国家字段?我也尝试了基本的 "Sst_Country_mc":"Spain",但没有用。

假设 Sst_Country_mc 是一个选择字段设置为允许多项选择...

在您的 REST 数据负载中,该字段的格式应为 object,其中 属性 称为 "results" 应该包含一个 数组 的字符串值。

"Sst_Country_mc": {
    "results":["Spain","Netherlands"]
}

您的最终数据负载可能如下所示:

{
    "__metadata": {"type": "SP.Data.SST_x0020_Requests_x0020_StagingListItem"},
    "Title":"Andrew Test 4",
    "Sst_Customer_Name_st":"Customer",
    "Sst_Business_Category_sc":"Finance and Insurance",
    "Sst_Country_mc": {
        "results":["Spain","Netherlands"]
    },
    "Sst_Actual_Request_mt":"",
    "Sst_E_Model_1_st":"MODEL",
    "Sst_E_Hardware_Qty_1_ni":"1",
    "Sst_Deadline_Validate_d":"01/01/2017",
    "Sst_Office_sc":"B UK"
}