0

Im new on SharePoint 2016 and i want "POST" items to list `

var data = JSON.stringify($scope.formData);  
console.log(data)
data = data.replace(/[{}]/g, '');  
var datavalue = "{__metadata:{'type':'SP.Data.Task_x0020_ScheduleListItem'}," + data + "}";  
$http({  
    url:"_api/web/lists/GetByTitle('Task%20Schedule')/items", 
   //url is working fine , I just took out complete url and placed end point here 
    method: "POST",  
    headers: {  
        "Accept": "application/json;odata=verbose",  
        "Content-Type": "application/json;odata=verbose",  
        "X-RequestDigest":digestValue,
        "X-HTTP-Method": "POST"  
    },  
    data: datavalue 
}).then(function(response) {  
    digestValue=" ";
    alert("success");  
}, function(response) {  
    alert("failed");  
});

could anyone please check what is wrong with this ? i have added digest value also but when I make post call i get this error

error: {code: "-1, Microsoft.SharePoint.Client.InvalidClientQueryException", message: {lang: "en-US",…}}
code: "-1, Microsoft.SharePoint.Client.InvalidClientQueryException"
message: {lang: "en-US",…}
lang: "en-US"
value: "A '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."

data that i am passing :

{__metadata:{'type':'SP.Data.Task_x0020_ScheduleListItem'},"Task_x0020_Type":"Reporting","Country":"America","Title":"a","Schedule_x0020_Type":"Monthly","Monthly_x0020_Type":"Day","Assignee":"results":["Title":"Lye, Nicholas"],"Escalation_x0020_Point":"results":["Title":"Lye, Nicholas"],"Due_x0020_Hour":"? undefined:undefined ?","Due_x0020_Min":"? undefined:undefined ?","Relevant_x0020_Documents":"ff###@http;://vv$$$","Monthly_x0020_Value":"30"}
  • 1
    This error is not related to digest value. This is due to the data you are passing is wrong(not according to data types of list columns). I guess there is wrong data after "Assignee" field in data. – Ganesh Sanap Dec 23 '18 at 13:19
  • If you can provide data types of the columns then it will be helpful to understand what is wrong. – Ganesh Sanap Dec 23 '18 at 13:20
  • Welcome. You can answer your own question below. So that others can get help from it, if they come across the same issue. – Ganesh Sanap Dec 24 '18 at 3:59
0

For multiple user filed, the JSON should be similar as

var itemProperties = {
    '__metadata' : { 'type':'SP.Data.Task_x0020_ScheduleListItem' },
    'Title': 'a',
    'AssigneeId' : { 'results': [user1id,user2id] }
}

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.