Please specify what version of the library you are using: [1.3.6]
Please specify what version(s) of SharePoint you are targeting: [onPrem 2016]
It should Update an Item in a CustomList after i call sp.web.lists.getByTitle('test').items.getItemByStringId('1').update(test);
Sharepoint just returns an Microsoft.SharePoint.Client.InvalidClientQueryException.
I manually created a Custom List in Sharepoint 2016 with the name 'test' and added one item with only a Title. Hence the ItemId 1 and the given Name for the List.
// Remove this if you don't have any code sample to provide
import { sp } from "@pnp/sp";
public static async testUpdate(){
return await sp.web.lists.getByTitle('test').items.getItemByStringId('1').update({
'Title': 'Another Title',
}).then(result => {
console.log(result);
});
}
After calling the above function through the workbench (spfx 1.1.0 gulp serve) on my running sharepoint instance (not local) i get the following scenario:
{
"odata.error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": {
"lang": "en-US",
"value": "An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified."
}
}
}
and after inspecting the request body i found this body without a metadata type:
{
"__metadata": {},
"Title": "Another Title"
}
after that i tested the following code with the correct type from the ListItemEntityTypeFullName call:
import { sp } from "@pnp/sp";
public static async testUpdate(){
return await sp.web.lists.getByTitle('test').items.getItemByStringId('1').update({
'__metadata': {'type': 'SP.Data.TestListItem'},
'Title': 'Another Title',
}).then(result => {
console.log(result);
});
}
And it worked without problems.
I don't know if i did something wrong but Adding Items and Deleting Items is working on different lists and also some Batch operations with Add/Delete. I also used the onInit() context setup for sp.
I hope someone can help here and find the real culprit.
Hi @Sedor,
It's not a bug.
getItemByStringId serves the purpose of working with BDC/BCS (external lists) it is not supported with native lists, getById should be used instead. For external lists __metadata is not required.
Hey @koltyakov,
Thanks for the fast help !
I tested your suggestion and it's working. I also saw the getItemByStringId description .... Didn't see the BCS part of it there.
Thanks again :)
Most helpful comment
Hi @Sedor,
It's not a bug.
getItemByStringIdserves the purpose of working with BDC/BCS (external lists) it is not supported with native lists,getByIdshould be used instead. For external lists__metadatais not required.