I'm learning to write SharePoint 2013 applications. I added menu item custom action, and now I'm trying to add some functionality to App.js. Custom action contains the following code:

<UrlAction Url="~appWebUrl/Pages/Default.aspx?{StandardTokens}&amp;SPListItemId={ItemId}&amp;SPListId={ListId}" />

And I'm trying to get parameters like "SPListItemId" and "SPListId" in App.js. I found the following code:

 function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));

I'm calling this function like, but it doesn't work:

var SPListId = getParameterByName('ListId');

Please tell me where is my mistake.


You need to use

var SPListId = getParameterByName('SPListId');
| improve this answer | |
  • Hey Kai. Thank you for answer. But the problem is still there. Function getParameterByName(name) uses only location.search, maby it should get data from the document? Or how to use getParameterByName('SPListId'); correctly? – Andrey Nuzha Nov 11 '16 at 14:12
  • You're right, it uses location.search, in other words it tries to get parameter value from you query string. For example for following url http://my.app.com/?SPListId=4 the function will return 4. If SPListId is missing from query string, it returns nothing. – Sergei Sergeev Nov 11 '16 at 14:24
  • When application has started, the document is loaded too. I got the applications url through the document, but there is no tag with ListId. From what object I can retrieve any staff to use getParameterByName? – Andrey Nuzha Nov 11 '16 at 15:04
  • Which List Id are you expecting on Pages/Default.aspx? – Sergei Sergeev Nov 11 '16 at 15:05
  • My action begins when the button in list item menu is activated. After that, the application is loaded on Default.aspx. I wanna get ItemId and ListId, where the application was called. I thought that this information can be obtained from a string <UrlAction Url="~appWebUrl/Pages/Default.aspx?{StandardTokens}&amp;SPListItemId={ItemId}&amp;SPListId={ListId}" /> by using JS script in App.js – Andrey Nuzha Nov 11 '16 at 15:15

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.