I have two custom actions that are currently deployed to a SharePoint 2013 Forms Library. They are working perfectly fine with the exception of a less than favorable method.
What happens now is that when the user clicks on the custom action, it then redirects to a Default.aspx page and then executes my JavaScript. Here is a very similar thread but it had contradicting answers: Call JavaScript function for a custom action in an app for SharePoint 2013
Here is the code:
Elements.xml for Menu Item Custom Action
NOTE: Whenever I do this, Visual Studio won't allow me to deploy the app due to how the UrlAction Url
is formatted.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="dbba1823-1524-4dd9-be18-0b1a547a2a32.LaunchApp"
RegistrationType="FileType"
RegistrationId="xml"
Location="EditControlBlock"
Sequence="10001"
ImageUrl="myPics/myImage.ico"
Title="Launch In Windows 8 app">
<!--
Update the Url below to the page you want the custom action to use.
Start the URL with the token ~remoteAppUrl if the page is in the
associated web project, use ~appWebUrl if page is in the app project.
-->
<UrlAction Url="~appWebUrl/Pages/Default.aspx?HostUrl={HostUrl}&ItemURL={ItemUrl}&Source={Source}" />
</CustomAction>
</Elements>
What I would like to do is take away the uneccessary step of redirecting to another page to execute that JavaScript. I would like it to be executed once the user hits the custom action. I have seen a few threads on this but none appear to work. This is basically what I want:
Preferred method in Elements.xml file
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="dbba1823-1524-4dd9-be18-0b1a547a2a32.LaunchApp"
RegistrationType="FileType"
RegistrationId="xml"
Location="EditControlBlock"
Sequence="10001"
ImageUrl="myPics/myImage.ico"
Title="Launch In Windows 8 app">
<!--
Update the Url below to the page you want the custom action to use.
Start the URL with the token ~remoteAppUrl if the page is in the
associated web project, use ~appWebUrl if page is in the app project.
-->
<UrlAction Url="../scripts/myScript.js" />
</CustomAction>
</Elements>
Current Attempt
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction ScriptSrc="~sites/Scripts/App.js" Location="ScriptLink" Sequence="1">
</CustomAction>
<CustomAction Id="decb57e5-4b37-4d87-af85-fd67173e4e91.RibbonAction"
RegistrationType="List"
RegistrationId="115"
Location="CommandUI.Ribbon"
Sequence="10001"
Title="action">
<CommandUIExtension>
<!--
Update the UI definitions below with the controls and the command actions
that you want to enable for the custom action.
-->
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Library.Settings.Controls._children">
<Button Id="Ribbon.Library.Settings.RibbonActionButton"
Alt="action"
Sequence="100"
Command="Invoke_RibbonActionButtonRequest"
LabelText="action"
TemplateAlias="o1"
Image32by32="https://mysite.sharepoint.com/sites/spdev/demo/SiteAssets/myicon.ico"
Image16by16="https://mysite.sharepoint.com/sites/spdev/demo/SiteAssets/myicon.ico" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="Invoke_RibbonActionButtonRequest"
CommandAction="javascript:myFunction();"/>
</CommandUIHandlers>
</CommandUIExtension >
</CustomAction>
</Elements>
Thanks in advance for any helpful input.