⚠️ Legacy — prefer SPFx Extensions for modern sites. Microsoft recommends migrating from UserCustomAction to SharePoint Framework (SPFx) Extensions. These examples target classic pages and lists only. Migration guide
Add custom functionality to classic SharePoint pages and lists — inject JavaScript, add toolbar buttons, or extend the ribbon.
| Requirement | Description | Reference |
|---|---|---|
| Site Owner role | Required to manage custom actions on a site or list. | SharePoint admin roles |
Custom actions can be created at two scopes:
- Site scope — ScriptLink injects JavaScript into every page
- List scope — adds toolbar buttons or ECB menu items to a specific list
| Step | Operation | File | Required role | API reference |
|---|---|---|---|---|
| 1 | List — enumerate site and list custom actions | list_actions.py |
Read access | List |
| 2 | Add script link — inject JavaScript site-wide | add_script_link.py |
Site Owner | Create |
| 3 | Add list action — add a toolbar button to a list | add_list_action.py |
Site Owner on target list | Create |
| 4 | Remove — delete a custom action by ID | remove_action.py |
Site Owner | Delete |
from office365.sharepoint.client_context import ClientContext
ctx = ClientContext("https://contoso.sharepoint.com/sites/team").with_client_secret(
"contoso.onmicrosoft.com", "client_id", "client_secret"
)
# List all custom actions on the site
actions = ctx.web.user_custom_actions.get().execute_query()
for a in actions:
print(f" {a.properties.get('Title', '')} (ID: {a.properties.get('Id', '')})")