In my SPFx webpart, I am utilizing PnPJS to set custom item level permissions on specific items within multiple lists. Below is the snippet of code I have written:
let listIds: string[] = [
"LISTGUID1",
"LISTGUID2"
];
for (const listId of listIds) {
const listItems: Item[] = await sp.web.lists
.getById(listId)
.items
.filter(`LookupFieldId eq ${lfId}`)
.get();
if (Validate.ArrayWithElements(listItems)) {
for (const item of listItems) {
await item.breakRoleInheritance(false);
await item.roleAssignments.add(userId, roleDefId);
}
}
}
An error occurs at this line:
await item.breakRoleInheritance(false, false);
The error message displayed is:
Uncaught (in promise) TypeError: item.breakRoleInheritance is not a function
I have also attempted explicitly casting the result to type Item
, but it still does not work. The Item
class extends SharePointQueryableShareableItem
, and SharePointQueryableShareableItem
extends SharePointQueryableSecurable
. The method is defined in the latter.