1

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.

1 Answer 1

0

You need to use

var SPListId = getParameterByName('SPListId');
7
  • 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? Commented Nov 11, 2016 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. Commented Nov 11, 2016 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? Commented Nov 11, 2016 at 15:04
  • Which List Id are you expecting on Pages/Default.aspx? Commented Nov 11, 2016 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 Commented Nov 11, 2016 at 15:15

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.