Forum Discussion
Add custom action with add-pnpcustomaction
Hello,
I'm trying to hide the delete button in SharePoint Online list ribbon; I tried with custom action and powershell but I'm blocked (see SPO custom action to hide delete button - Microsoft Tech Community ).
With other research I find that, maybe, is possible to add a custom action with the powershell cmdlet add-pnpcustomaction of Pnp.PowerShell module; I have seen the syntax of the cmdlet but I don't understand some thing; I have a list, only a SPO list, where I want to apply the custom action: is it possible?
Say I have the mytenant.sharepoint.com/sites/testsite where I have some lists, but I want to hide the delete button in the mytestlist: how to reference it in the command?
From some sample found online and also from the documentation sample I write something like this:
Connect-PnPOnline -Url "https://mytenant.sharepoint.com/sites/testsite" -Interactive
$cUIExtn = "<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=""Ribbon.ListItem.Manage.Delete"" /></CommandUIDefinition></CommandUIDefinitions></CommandUIExtension>"
Add-PnPCustomAction -Name 'HideDeleteButton' -Title 'HideDeleteButton' -Location 'CommandUI.Ribbon' -RegistrationType List -Sequence 10000 -RegistrationId 101 -CommandUIExtension $cUIExtn
But, my 2 questions are:
- is it correct
- how or where reference the list?
Any help is appreciated.
--
Regards
1 Reply
- AAminMBrass Contributor
Hi MarcoMangianteIM,
You can hide actions in command bar in modern experience using View formatting. More information about this can be found https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/view-formatting and https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/view-commandbar-formatting.
To hide the Delete button from the commandbar, the view formatting code should be as follows:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/tile-formatting.schema.json", "commandBarProps": { "commands": [ { "key": "delete", "hide": true } ] } }
Note: this is hiding the delete button from command bar, but still will be shown in the file/item context menu. If needed to be removed completely, I would prefer then controlling this using permissions by creating a new https://sharepointmaven.com/how-to-create-a-custom-permission-level-in-sharepoint/, i.e., to allow users to create, and edit items, but not to delete items.