#StackBounty: #sharepoint-server #javascript #sharepoint-on-prem #custom-actions #custom-list-actions Register Custom Action with Javas…

Bounty: 50

I am having difficulty registering a custom user action through JavaScript. I am using the following code example. The code executes without any error however the button fails to appear on the Ribbon. I am hoping someone maybe able to point out where I have gone wrong

var clientContext = SP.ClientContext.get_current();
var oWeb = clientContext.get_web();
var oList = oWeb.get_lists().getByTitle(listTitle);
var userCustomActionColl = oList.get_userCustomActions();

clientContext.load(oList, 'UserCustomActions', 'Title');
clientContext.executeQueryAsync();

var oUserCustomAction = userCustomActionColl.add();
oUserCustomAction.set_location('CommandUI.Ribbon.EditForm');
oUserCustomAction.set_sequence(1);
oUserCustomAction.set_title("Related Items -" + fieldDisplayName);
var uiExtension = '<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">' +
            '<CommandUIDefinitions>' +
                '<CommandUIDefinition Location="Ribbon.ListForm.Edit.Actions.Controls._children">'+
                    '<Button Id="RibbonTest2" '+
                            'Command="TestCommand" '+
                            '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="TestCommand" '+
                    'CommandAction="javascript:SP.UI.Notify.addNotification('Hello from the notification area');" />'+
            '</CommandUIHandlers>'+
           '</CommandUIExtension>';

oUserCustomAction.set_commandUIExtension(uiExtension);
oUserCustomAction.set_registrationId(_spPageContextInfo.pageListId);
oUserCustomAction.set_registrationType(1);
oUserCustomAction.update();
clientContext.load(userCustomActionColl);
clientContext.executeQueryAsync();


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.