Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 at 23:57

3 Answers 3

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

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 http://msdn.microsoft.com/en-us/library/bbd11f94-1798-453e-bbb0-e5eb0df8dc75. 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 (msdn.microsoft.com/en-us/library/fp179927.aspx)? –  C. Marius - MVP Feb 19 '13 at 9:50
i want to call a javascript function(resides in App.js) in the url action.how to do it? –  user10000 Mar 4 '13 at 9:30

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 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.