我需要将项目插入到sharepoint列表中,该列表包含多个列,例如ticket id,EmpID和ShareTicketWith,这是peoplepicker字段。当我没有通过人员选择列时,我能够插入记录。但是,当我通过人员选择器列时,它会抛出错误"PrimitiveValue' node with non-null value was found when trying to read the value of a navigation property; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected."}}}"
。
我尝试了多种方法来传递它,但每次都会抛出错误。以下是代码:
var sharedticketlist= {
"__metadata": { 'type': 'SP.Data.TestTicketListListItem'},
"Title": "1241",
"EmpID":"123456",
"TicketSharedWith":"test@test.com",
}
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('TestTicketList')/items",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify(sharedticketlist),
success: function(data) {
console.log(data.d.results);
},
error: function(error) {
alert(JSON.stringify(error));
}
});
我也试过传递作者ID,但它仍然没有用。任何帮助表示赞赏。
答案 0 :(得分:0)
请检查下面的Rest OData xml,它应该为用户ID的这两个字段设置EmpIDId和TicketSharedWithId,例如,我当前的用户ID为10,然后设置如下:
<script type="text/javascript">
var sharedticketlist= {
"__metadata": { 'type': 'SP.Data.TestTicketListListItem'},
"Title": "1241",
"EmpIDId":10,//this is user id, replace with yours
"TicketSharedWithId":10 //this is user id, replace with yours
}
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('TestTicketList')/items",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify(sharedticketlist),
success: function(data) {
console.log(data.d.results);
},
error: function(error) {
console.log(JSON.stringify(error));
}
});
</script>
休息OData:
结果: