0

How to add a link(Custom action) to a document library page's Ribbon with java script. And where to add that java-script? please help.

0

You can add the Ribbon Button using JavaScript API. You need to add the script in Content Editor or Script Editor Web Part

    var context = new SP.ClientContext.get_current();
this.site = context.get_web();
var customAction = this.site.get_userCustomActions().add();
customAction.set_location('CommandUI.Ribbon.NewForm');

var uiExtension = '<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">' +
                        '<CommandUIDefinitions>' +
                            '<CommandUIDefinition Location="Ribbon.ListForm.Edit.Commit.Controls._children">'+
                                '<Button Id="Ribbon.Documents.New.RibbonTest" '+
                                        'Command="PrintPage" '+
                                        'Sequence="0" '+
                                        'Image16by16="/_layouts/images/NoteBoard_16x16.png" '+
                                        'Image32by32="/_layouts/images/NoteBoard_32x32.png" '+
                                        'Description="Uses the notification area to display a message." '+
                                        'LabelText="Notify hello" '+
                                        'TemplateAlias="o1"/>' +
                            '</CommandUIDefinition>'+
                        '</CommandUIDefinitions>'+
                        '<CommandUIHandlers>'+
                            '<CommandUIHandler Command="PrintPage" '+
                                'CommandAction="javascript:SP.UI.Notify.addNotification(\'Hello from the notification area\');" />'+
                        '</CommandUIHandlers>'+
                       '</CommandUIExtension>';

customAction.set_commandUIExtension(uiExtension);

customAction.set_registrationId("0x0108");
customAction.set_registrationType(SP.UserCustomActionRegistrationType.contentType);

customAction.update();

context.load(this.site,'UserCustomActions');

context.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
        Function.createDelegate(this, this.onFailure)); 

SP.UserCustomActionCollection Class

Please refer the Link

Or else simply you can use SharePoint Designer to add the Custom Ribbon Action using SPD2013

  • i am trying to add this code in content editor in a document library page. But after adding the code, even the ribbon stops appearing in the page. Same is with script editor web part. – Adarsh Awasthi Nov 8 '17 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.