Question

Like the title says, I am trying to hide the "New Item" Button that is located in the Ribbon of a custom SharePoint 2013 list. I have already achieved this using CSS, but I am looking for a way to do this with Custom Actions. I have come across the HideCustomAction element, but have not yet made it work.

Has anyone done this before or does anybody know what I'm doing wrong? Is this even achievable with Custom Actions?

enter image description here

Here is what I have so far (315005 is the Template Id of my custom list):

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <HideCustomAction
    GroupId = "Ribbon.ListItem.New"
    HideActionId = "Text"
    Id = "315005"
    Location = "Ribbon.ListItem.New.NewListItem">
  </HideCustomAction>
</Elements>

Ok, I have managed to hide all "New Item" Buttons with the following Custom Action:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <CustomAction
    Id="RemoveRibbonButton"
    Location="CommandUI.Ribbon">
      <CommandUIExtension>
        <CommandUIDefinitions>
          <CommandUIDefinition
            Location="Ribbon.ListItem.New.NewListItem" />
        </CommandUIDefinitions>
      </CommandUIExtension>
  </CustomAction>
</Elements>

The only problem is now, I need to make this apply only to my custom list. So I have tried adding RegistrationType and RegistrationId properties, but the button isn't removed. Any ideas why?

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <CustomAction
    Id="RemoveRibbonButton"
    Location="CommandUI.Ribbon" 
    RegistrationId="315005" 
    RegistrationType="List">
      <CommandUIExtension>
        <CommandUIDefinitions>
          <CommandUIDefinition
            Location="Ribbon.ListItem.New.NewListItem" />
        </CommandUIDefinitions>
      </CommandUIExtension>
  </CustomAction>
</Elements>

EDIT: I tested this on another custom list (315010) and it works with that list's Template Id. However, I have also a EvenReceiver that's attached to my 315005 list and it works. The EventReceiver also uses the TemplateId to reference the list it's attached to.

Was it helpful?

Solution

OK I have found the problem. Besides hiding the Ribbon "New Item" Button, I also wanted to hide the "New item or edit this list" link above the ListViewWebPart. I have found a blog online where the guy said that in order to do that, I needed to set <Toolbar Type="None" /> in the list's Schema.xml file. It worked, but apparently it also broke the ribbon somehow. Once I set it again to the default value of <Toolbar Type="Standard" />, my custom action worked.

Very weird.

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