A ListView Command Set extension in SharePoint allows you to customize the command bar (toolbar) of lists or libraries by adding new actions. These actions can be tailored to perform custom business logic, navigate users to specific locations, or integrate with external systems.
- Custom Commands
- Add new buttons to the command bar or context menu in list/library views.
- Define actions triggered by these commands.
- Context-Sensitive Actions: Execute different logic based on the selected item(s) or list context.
- Integration: Connect with third-party APIs, open dialogs, or launch forms.
Step 1. Generate the SPFx Extension.
Step 2. When prompted, enter the following values.
- What is your solution name?: command-extension
- Which type of client-side component to create?: Extension
- Which type of client-side extension to create?: ListView Command Set
- What is your Command Set name?: HelloWorld
Step 3. Open the file ./src/extensions/helloWorld/HelloWorldCommandSet.ts.
Modify the onExecute method to define the action triggered by your custom command.
Step 4. Update the Manifest.
Open the ./src/extensions/helloWorld/HelloWorldCommandSet.manifest.json file.
This file defines your extension type and a unique identifier id for your extension. You need this unique identifier later when debugging and deploying your extension to SharePoint.
Step 5. Open ./config/serve.json file. Update the page URL attributes to match the URL of the list where you want to test the solution.
Step 6. Build, Package, and Deploy.
Run the following commands one by one.
Step 7. Upload the package.
Upload the .sppkg file from the SharePoint/solution folder to your App Catalog.
Step 8. Navigate to the SharePoint list or library where the extension is applied.
- Look for the new commands added to the toolbar or context menu.
- Execute the commands and verify their functionality.
Output
Command 1. When you click on "Alert", a simple alert message appears.
“Command 1 executed!”
Command 2. When you select one or more items in the list and click "Show Selected Items," it displays the titles of the selected items in an alert box.
A ListView Command Set extension is a simple and effective way to add custom actions to SharePoint lists and libraries. It lets you create buttons that perform specific tasks, like automating workflows, showing custom messages, or connecting to other systems.
0 comments:
Post a Comment