Not able to insert data into TaskList In sharepoint Spfx
-
20-02-2021 - |
题
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."
解决方案
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.
其他提示
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] }