pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
988 stars 662 forks source link

Need to add custom button to SharePoint List View Ribbon #2231

Open hbash2020 opened 5 years ago

hbash2020 commented 5 years ago

Using 2016 PnP latest.

I have this pnp script which adds a button to a list view ribbon.

It runs and I can delete the button in script and know that is was there and deleted by count. But, the pnp script to add the button doesn't work until after I had run a console app to add a button to the list.

It is as though some structure needs to be setup that the pnp script isn't doing and the console app does.

Here is the pnp script: `$cUIExtn = "<CommandUIDefinition Location=""Ribbon.ListItem.Actions.Controls._children""> <Button Id=""Ribbon.List.Items.Action.MyButton"" Alt=""Promote Request"" Sequence=""03"" Command=""ShowPromoMoreButtons"" LabelText=""Promote Selected"" TemplateAlias=""o1"" Image32by32=""/sites/Practice/images/Perspective-Button-Reboot-icon-32.png"" Image16by16=""/sites/Practice/images/Perspective-Button-Reboot-icon-16.png"" />

"

Add-PnPCustomAction -Name "MoreButtonsReq" -Title "Promote This" -Description "MoreButtonsReq" -Location "CommandUI.Ribbon" -Group "SiteActions" -RegistrationType List -registrationId "{gggggggg-gggg-421a-gggg-246b00ef7a82}" -Rights EditListItems -Scope Web -CommandUiExtension $cUIExtn `

Here is the console app c#: ` SPSite osite = new SPSite(SiteURL);

            SPWeb oweb = osite.OpenWeb();
            SPList olist = oweb.Lists[ListName];

            //Add New SPUserCustomAction            
            SPUserCustomAction action = olist.UserCustomActions.Add();

            foreach (var customAction in olist.UserCustomActions)
            {
                string extension = customAction.CommandUIExtension;
                if (extension.IndexOf("PROMOTION") > 0)
                {
                    Console.WriteLine("Found PROMOTION Button and removing before adding updated version");
                    customAction.Delete();
                    olist.Update();
                    break;
                }
            }

            //Location of the action should be ribbon..           
            action.Location = "CommandUI.Ribbon";

            //This one is Optional as we are adding the same later
            action.ImageUrl = Image32;

            //This is the major input..
            action.CommandUIExtension = @"<CommandUIExtension>" +
                    "<CommandUIDefinitions><CommandUIDefinition Location='Ribbon.ListItem.Actions.Controls._children'>" +
                        " <Button Id='Ribbon.List.Items.Action.MyButton' " +
                                "Sequence='03' " +
                                "Alt='MyCustom' " +
                                "Command='testToShow' " +
                                "Image16by16='" + Image16 + "' " +
                                "Image32by32='" + Image32 + "' " +
                                "LabelText='Promote It' " +
                                "ToolTipTitle='Promote item' " +
                                "ToolTipDescription='Click to Promote' " +
                                "TemplateAlias='o1'></Button>" +
                    "</CommandUIDefinition></CommandUIDefinitions>" +
                    "<CommandUIHandlers>" +
                    "<CommandUIHandler Command='testToShow' " +
                                        "CommandAction='javascript: PROMOTION.clickMethod();'>" +
                        "</CommandUIHandler>" +
                    "</CommandUIHandlers>" +
                    "</CommandUIExtension>";

            action.Update();

`

ghost commented 5 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.