Question

Hi i am trying below code to move document from Documents library to SiteAssets library , but how to make it dynamic so selected document will be move to destination library

  @override
  public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
    const destinationUrl = `/sites/test/SiteAssets/new-file.docx`;
    switch (event.itemId) {
      case 'COMMAND_1':
        
     sp.web.getFileByServerRelativePath("/sites/test/Documents/test.docx").moveTo(destinationUrl);

        break;
      case 'COMMAND_2':
       // Dialog.alert(`${this.properties.sampleTextTwo}`);
        break;
      default:
        throw new Error('Unknown command');
    }
  }
Was it helpful?

Solution

you need to get the selected items in library. You can obtain those by using event.selectedRows. The code should look like below

@override
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
  switch (event.commandId) {
      case 'COMMAND_1':
          // Check if the user selected some items
          if (event.selectedRows.length > 0) {
              // Check the selected rows
              event.selectedRows.forEach((row: RowAccessor, index: number) => {
                  //Add the code to move files
              });
          }
          break;
      default:
          throw new Error('Unknown command');
  }
}

OTHER TIPS

You could get selected item id/FileRef in event.

This a screen shot of event: enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top