I inherited a custom application from another developer who used REST API to create list items. Now the requirement is to add a multiple users people picker to the form.
I am able to add a multiple people picker to the form. However when I am trying to save I get this error "A node of type 'startArray' was read from the JSON reader when trying to read a value of property; however, a 'PrimitiveValue' or 'StartObeject' node was expected"
I understood from other blogs that the syntax should be "RequestorId": { "results": [106,111] }. But my problem in my code is to have this value in a variable and then push into an array and pass it into the function which does the creation of an item. What I am struggling here is the syntax for that variable.
Should I include the curly brackets as well {}
var colsAndValues = [];
var peoplepicker1 = SPClientPeoplePicker.SPClientPeoplePickerDict.elvlglENotification_TopSpan;
if (peoplepicker1 != null) {
var users = peoplepicker1.GetAllUserInfo();
if (users.length == 0) {
//alert("No users");
// Mutiple User/Lookup value format: {FieldName: {"results": [LookupIdVal1,LookupIdVal2] }}
colsAndValues.push("RequestorId");
var UserValue = "'results'"+":[0]";// Not sure if this is right syntax. Here is where I feel my problem is
colsAndValues.push(UserValue);
}
//Function for creating the list item
var item = {
"__metadata": { "type": itemType }
};
for(var i = 0; i < colsAndValues.length; i++) {
if (i % 2 !== 0) {
item[colsAndValues[i-1]] = colsAndValues[i];
}
}
var siteurl = _spPageContextInfo.webAbsoluteUrl;
jQuery.ajax({
url: siteurl + "/_api/web/lists/getbytitle('" + listName + "')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
},