Question

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

Was it helpful?

Solution

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

OTHER TIPS

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] } 
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top