Im working on a pretty simple spfx CommandSet extension. Its goal is to duplicate an item, when an item is selected. I have the working code. My problem is, that i searched the context property, but could not find a method, to update the ListView, to show the newly created(duplicated) item. (By default it not shows the created item because i created it with an API call)
Code:
@override
public onListViewUpdated(event: IListViewCommandSetListViewUpdatedParameters): void {
const duplicateCommand: Command = this.tryGetCommand('DUPLICATE_ITEM');
if (duplicateCommand) {
duplicateCommand.visible = (event.selectedRows.length === 1);
}
}
@override
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
switch (event.itemId) {
case 'DUPLICATE_ITEM': this.DuplicateItem(event); break;
default: throw new Error('Unknown command');
}
}
private DuplicateItem(event: IListViewCommandSetExecuteEventParameters): void {
//stuff to do
pnp.sp.web.lists.getByTitle(listName).items.add(data)
.then((result: any) => {
//refresh ListView to show new item
}).catch(error => {
//error handling
});
}
How can i do this?