Question

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();
Was it helpful?

Solution

After parking it for a few days i have managed to get it working by removing the following calls:-

  • set_location

  • set_registrationId

  • set_registrationType

  • set_sequence

I have also removed the icon references because they were invalid.

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