簡體   English   中英

使用Rest API將人員選擇器列插入Sharepoint列表

[英]Insert people picker column to Sharepoint list using Rest api

我需要將項目插入共享點列表,該列表具有多個列,如票證ID,EmpID和ShareTicketWith,這是人員選擇字段。 當我不通過人員選擇器列時,我可以插入記錄。 但是,當我通過人員選擇器列"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."}}}"會拋出錯誤"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,但仍然無法正常工作。 任何幫助表示贊賞。

請檢查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:

數據

結果:

結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM