2016-12-01 57 views
0

我有一些field.I的SharePoint列表正在使用Javascript执行下列操作张贴到列表:SharePoint Online中过帐项与元素字段列表

$.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"); 
    } 
}); 

,这是工作奇妙。问题是,我的领域之一,当我使用邮递员是likeso:

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

但这种失败,出现以下错误:

找到了一个没有“结果”属性的集合。在OData中,每个集合必须表示为具有属性“结果”的JSON对象。

这不是我如何发布,因为当我删除该字段,它的工作原理,但我需要填充这个字段填充项目创建的工作流程。

我应该如何格式化我的JSON来处理country字段?我尝试了一个基本的“Sst_Country_mc”:“西班牙”也没有工作。

回答

1

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

在您的REST数据有效载荷,该字段应该是在对象的一个叫做属性的格式“结果”这应该包含字符串值的数组

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