When I submit the info to the list, I was getting the following error (which I assume is due to trying to incorrectly post to a Person or Group column:
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.
So in my item I am sending I changed my Person or Group field value from
"Employee" : employeeName,
//to
"Employee": {
"results" : employeeName
},
and this causes me to a get a new error:
value: "Value cannot be null.\r\nParameter name: entitySet"
I have also tried posting to the Person or Group field like so,
"Employee": {
"results" : {
"__metadata" : { type: "SP.Data.UserInfoItem"},
"Title" : employeeName
}
},
and to no surprise, I get the same error. The original I tried posting to a Single line of text field and it worked.
UPDATE
Here is the update to the item I am trying to post per Ganesh's answer, and I am still getting the same answer.
const employeeName = $("#empName").val();
const daySelect = $("#daySelect").val();
const startDate = $("#startDate").val();
const endDate = $("#endDate").val();
const totalHours = $("#totalHours").val();
const leavePurpose = $("#leavePurpose").val();
const totalPTO = $("#totalPTO").val();
var myUserId = _spPageContextInfo.userId; // To get current user ID
const item = {
"Title": newItemTitle,
"Employee": {
"Title" : employeeName,
"Id" : myUserId
},
"FullorPartial": daySelect,
"StartDate": startDate,
"EndDate": endDate,
"TotalHrs": totalHours,
"LeavePurpose": leavePurpose,
"AvailablePTO": totalPTO
};
employeeName
? You have to pass the user "ID" to set the person or group field. User display name or email will not work.