0

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
              };
1
  • 1
    What value is stored in employeeName? You have to pass the user "ID" to set the person or group field. User display name or email will not work. Jun 27 at 16:33

1 Answer 1

0

Person or Group fields are special fields in SharePoint. You cannot just pass the text (user display name or email address) to set the person or group field like single line of text field.

To set person or group field, you hav to pass the user ID.

Example:

To set the current user in person or group field use below code:

var userId = _spPageContextInfo.userId; // To get current user ID
var itemProperties={Title:"New Item",EmployeeId:userId};

Note ID added after the internal name of person or group column.


Update from comments:

No need to pass the employee name to person or group field. Only pass the ID like:

const item = {
              "Title": newItemTitle,
              "EmployeeId": myUserId,
              "FullorPartial": daySelect,
              "StartDate": startDate,
              "EndDate": endDate,
              "TotalHrs": totalHours,
              "LeavePurpose": leavePurpose,
              "AvailablePTO": totalPTO
              };

If Employee column allows multiple selection, use this:

const item = {
              "Title": newItemTitle,
              "Employee": { 'results': [myUserId] },
              "FullorPartial": daySelect,
              "StartDate": startDate,
              "EndDate": endDate,
              "TotalHrs": totalHours,
              "LeavePurpose": leavePurpose,
              "AvailablePTO": totalPTO
              };
3
  • That makes since, the value I am passing into employeeName is an name as a string which I am trying to send to the people or group column. I tried with the userId and and it is still giving me the same error. I even hard coded my userId to test. "Employee": { "Title" : employeeName, "Id" : myUserIdVal },. My userIdVal is the value I hard coded with my userId
    – BeerusDev
    Jun 27 at 17:23
  • Please see the update to my original post
    – BeerusDev
    Jun 27 at 17:30
  • Hi @BeerusDev, does this help you in any way? If yes, please Upvote(^) and accept as an Answer as it helped you & it will help others with similar question in future to find the correct answer easily. It also removes this question from "Unanswered questions" list. Aug 24 at 14:40

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.