In my previous post, showed how to add custom user action through PowerShell CSOM. I have re-written the same script in a new school method using the OfficeDev/PnP-PowerShell cmdlets. As a pre-requisite make sure to install the cmdlets through the binaries available in the GitHub repository. For On-Premises install v15 version and v16 version for Office 365. Post installing, use the below snippet in PowerShell window.
Happy coding! Peace!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connect-SPOnline –Url https://yoursite.sharepoint.com –Credentials (Get-Credential) | |
$cUIExtn = "<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=""Ribbon.List.Share.Controls._children""><Button Id=""Ribbon.List.Share.GetItemsCountButton"" Alt=""Get list items count"" Sequence=""11"" Command=""Invoke_GetItemsCountButtonRequest"" LabelText=""Get Items Count"" TemplateAlias=""o1"" Image32by32=""_layouts/15/images/placeholder32x32.png"" Image16by16=""_layouts/15/images/placeholder16x16.png"" /></CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers><CommandUIHandler Command=""Invoke_GetItemsCountButtonRequest"" CommandAction=""javascript: alert('Total items in this list: '+ ctx.TotalListItems);"" EnabledScript=""javascript: function checkEnable() { return (true);} checkEnable();""/></CommandUIHandlers></CommandUIExtension>" | |
Add-SPOCustomAction -Name 'ff1591d2-8613-4a1c-b465-d647a34b2555-GetItemsCount' -Title 'Invoke GetItemsCount Action' -Description 'Adds custom action to custom list ribbon' -Group 'Microsoft.SharePoint.Client.UserCustomAction.group' -Location 'CommandUI.Ribbon' -CommandUIExtension $cUIExtn |
Happy coding! Peace!!
Comments
Post a Comment