0

I am trying to create a SharePoint hosted app(for Sp 2013 & 0365) in VS 2013 for adding a ribbon action to site pages, to be shown while editing pages in it.

I am able to populate the button on the edit menu of a page by using the below code:

<CommandUIExtension>
  <CommandUIDefinitions>
    <CommandUIDefinition
      Location="Ribbon.EditingTools.CPInsert.Media.Controls._children">
      <Button Id="Ribbon.EditingTools.CPInsert.Media.RibbonCustomAction1Button"
              Alt="RibbonCustomAction"
              Sequence="100"
              Command="Invoke_RibbonCustomAction1ButtonRequest"
              LabelText="Request RibbonCustomAction1"
              TemplateAlias="o1"
              Image32by32="_layouts/15/images/placeholder32x32.png"
              Image16by16="_layouts/15/images/placeholder16x16.png" />        
    </CommandUIDefinition>        
  </CommandUIDefinitions>
  <CommandUIHandlers>
    <CommandUIHandler Command="Invoke_RibbonCustomAction1ButtonRequest"
                     CommandAction="~appWebUrl/Pages/Default.aspx?{StandardTokens}&amp;SPListItemId={SelectedItemId}&amp;SPListId={SelectedListId}"/>
    </CommandUIHandlers>
</CommandUIExtension >

But the issue is that I am not able to add CommandAction as below:

CommandAction="javascript:alert('Test');"

and is getting the below error on deployment:

Error occurred in deployment step 'Install app for SharePoint': There were errors when validating the App Package.

And hence the app is not working. Could you please let me know how to call js here?

1 Answer 1

0

You cannot add anything else but Urls into the CommandAction Property in SharePoint Hosted AddIns (taken from here -> search for 'CustomAction cannot contain Javascript').

An argumentation why Microsoft designed it this way can be found in this article (search for 'CommandAction="javascript:LaunchApp').

It seems that the app package is processed on import and certain urls get enhanced to enable the ~appWebUrl Token.

Possible duplicate with:

https://stackoverflow.com/questions/35759722/sharepoint-o365-custom-ribbon-action

1
  • thanks for the update @tashunko. the ultimate aim to have an java script action to execute on the button click. so please let me know for any alternative approaches for achieving it. thanks in advance
    – Scarlet959
    Commented May 17, 2017 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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