3

In “ribbon custom action” in SharePoint Online I want to invoke JavaScript code direct once click on the ribbon button rather than redirect to any aspx page (~appWebUrl/Pages/Default.aspx). But whenever I add JavaScript code in Elements.xml within CommandAction (see xml code below) :

<CommandUIHandlers>
        <CommandUIHandler Command="Invoke_Ribbon1ButtonRequest"
                          CommandAction="javascript: alert('Hello');"/>
      </CommandUIHandlers>
    </CommandUIExtension >

Deployment doesn’t work, and generates this error:

Error occurred in deployment step ‘Install app for SharePoint’: There where errors when validating the App Package.

Any suggestion? Thanks

2

Your CommandUIExtension should look like below:

    <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
                            <CommandUIDefinitions>
                                <CommandUIDefinition Location="Ribbon.List.CustomizeList.Controls._children">
                                    <Button Id="Ribbon.Documents.New.RibbonTest"
                                            Command="Notify"
                                            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="Notify"
                                    CommandAction="javascript:SP.UI.Notify.addNotification(\'Hello stackoverflow\');" />
                            </CommandUIHandlers>
                           </CommandUIExtension>

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.