SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on App for sharepoint 2013. I want to add custom action to a context menu of a document library.And I want to call a javascript function with selected item id and list id as parameters.javascript function is placed in the app.js file. I am using VS 2012 to add the custom action for the menu.

UrlAction Url="javascript:getItemDetails({ItemId},{ListId})"

I tried to call the javascript function using URLAction in element.xml file as I use to do it in SP 2010.But I am getting below error.

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

And then I placed a simple javascript alert.That also not worked and I got the same error.

If anybody knows the fix,please help me.

share|improve this question
Did anything come out of this? I'm running into the same issue and cannot find any great answers out there. This definitely seems like it should be possible... – mwilson Aug 6 '14 at 23:57

According to MSDN that is not possible:

CustomAction cannot contain JavaScript: Any UrlActions or CommandActions must be a URL to navigate to. The URL can be parameterized with normal custom actions tokens in addition to the app-specific tokens.

Also in ULS:

Custom action urls must start with "http:", "https:", "~appWebUrl" or "~remoteAppUrl".

You might want to try using HostWebDialog="TRUE" and reference a page from Application Web.

share|improve this answer
The MSDN documentation is actually wrong. You can write JS in the URL attribute as long as you include the full code in the attribute, namely include the function definition in the attribute before the function call. Defining the function somewhere else outside the attribute will not work. Also, you can write an IIFE (Immediately Invoked Function Expression) to make the code shorter. See example here. – Mihail Popa Jan 6 at 12:30

You must be missing something, or done some changes to your package which invalidates it. SharePoint 2013 does support Custom Actions in Ribbon and ECB, even in SharePoint Apps.

This example gives a full working example The major difference is how you use Tokens to address the Host Web or Client Web. Here is an excerpt from the article showing the exact definition of the Custom action Elements.xml

<?xml version="1.0" encoding="utf-8"?>
    <!-- RegistrationId attribute is the list type id,
        in this case, a document library (id=101). -->
      Title="Invoke custom action">
    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=
"~remoteAppUrl/CustomActionTarget.aspx?HostUrl={HostUrl}&amp;Source={Source}&amp;ListURLDir={ListUrlDir}&amp;ListID={ListId}&amp;ItemURL={ItemUrl}&amp;ItemID={ItemId}" />
share|improve this answer
Hi Marius, Thank you for ur response.I followed the same example.But in this example when this url action will redirect the user to another page.But i don't want the user to redirected to another page.Instead i want to call a javascript function to update another one list.I have done the same in sharepoint 2010.It works fine.But here only it's giving error.I want to fix this issue. – user10000 Feb 19 '13 at 5:52
the main issue you are facing is that the app model is functioning differently and updating a list might mean crossing site collections boundaries. have you considered using the cross-domain libraries ( – Marius Constantinescu - MVP Feb 19 '13 at 9:50
i want to call a javascript function(resides in App.js) in the url to do it? – user10000 Mar 4 '13 at 9:30

Mihail Popa is incorrect in his comment from Jan 6 2016 at 12:30. The MSDN documentation is not wrong. The question pertains to SharePoint 2013 app development. The example linked to in the comment is for SharePoint 2010 solution development. "SharePoint > SharePoint 2010 - Development and Programming" - it couldn't be clearer. In SP 2013 app development (now called add-in development), javascript is not allowed in custom actions, no matter how you write it, at least not when the customization is in the host app. I really wish that it was.

share|improve this answer

I had the same issue on SharePoint Online, you should us some other attributes, please follow this link:

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Please add potential part of the post in your answer, link only answers are to get void if the link is broken. – Arsalan Adam Khatri Nov 13 '14 at 21:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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