使用Rest api将人员选择器列插入Sharepoint列表

问题描述 投票:0回答:1

我需要将项目插入到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":"[email protected]",
}

   $.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,但它仍然无法正常工作。任何帮助表示赞赏。

javascript rest sharepoint sharepoint-online
1个回答
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:

OData

结果:

Result

© www.soinside.com 2019 - 2024. All rights reserved.