2

Using SP-Pnp-Js Library, I am not able to insert data from a webpart into the sharepoint Tasklist.

private SubmitWorkflowForm(): void {

var TaskNameVal = document.getElementById('taskName')['value'];
var StartDateVal = document.getElementById('startDate')['value'];
var DueDateVal = document.getElementById('dueDate')['value'];
var AssignedToVal = document.getElementById('assignedTo')['value'];
var CompleteVal = document.getElementById('complete')['value'];
var DescriptionVal = document.getElementById('description')['value'];
var PriorityVal = document.getElementById('priority')['value'];
var statusVal = document.getElementById('Status')['value'];

const siteurl: string = this.context.pageContext.site.absoluteUrl + "/_api/web/lists/getbytitle('TestTask')/items";
pnp.sp.web.lists.getByTitle("TestTask").items.add({
  Title: TaskNameVal,
  StartDate: StartDateVal,
  DueDate: DueDateVal,
  PercentComplete: CompleteVal,
  AssignedTo: AssignedToVal,
  Body: DescriptionVal,
  Priority: PriorityVal,
  Status: statusVal,
}).then(r => {
  alert('Success')
  $("input").val("")
  location.reload();
})
}

In the AssignedTo variable, I am using the "Users Email's value

Error- "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."

1
  • Assigned to field requires the ID of person/user. Jan 14, 2021 at 6:21

2 Answers 2

3
pnp.sp.web.lists.getByTitle("TestTask").items.add({
  Title: TaskNameVal,
  StartDate: StartDateVal,
  DueDate: DueDateVal,
  PercentComplete: CompleteVal,
  AssignedToId: [AssignedToVal],
  Body: DescriptionVal,
  Priority: PriorityVal,
  Status: statusVal,
}).then(r => {
  alert('Success')
  $("input").val("")
  location.reload();
})

Try modifying your code as above...

If your people and group column look like below.

AssignTo Column Settings

2
  • 1
    It worked like a charm ... Thanks a lot ..
    – abhishek23
    Jan 15, 2021 at 12:39
  • Are you able to add the user data to Assigned to field using Email address of user?? Jan 15, 2021 at 12:57
2

AssignedTo field expects the ID of person/user and not email address.

You need set this field like:

AssignedToId: 3

Where 3 is ID of user.

Additional Reference:

How to get the User Principle ID based on the Email Id


For multiple selection person or group field you need to use:

AssignedToId: { results: [3,11,100] } 

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.