2

I'm currently trying to find out, how to get a reference to currently selected list in sharepoint from javascript. I can get it if I know the title, or id, but I want it to get the list dynamically depending on where the user is. I have this code (in my modal dialog):

ExecuteOrDelayUntilScriptLoaded(init, 'sp.js');

function init() {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());
}

The problem is that SP.ListOperation.Selection.getSelectedList() returns null. There is probably some other script I need to wait for - but which one?

Mark Mascolino
  • 2,227
  • 1
  • 15
  • 19
Necros
  • 3,004
  • 23
  • 29
  • Related Q&A on SharePoint.SE about the current list item, maybe it will help: http://sharepoint.stackexchange.com/questions/11169/how-do-you-get-the-current-list-item-in-javascript – Kit Menke Jun 21 '11 at 14:12

2 Answers2

3

I figured it out. SP.ListOperation.Selection.getSelectedList() doesn't work inside of a modal dialog. I needed to pass list ID from the parent window.

Necros
  • 3,004
  • 23
  • 29
0

You may have found a bug in SharePoint web services (not that that's particularly surprising, given the sparseness of their API).

See here. I didn't look too carefully but BananaRepublic seemed to have a workaround for this problem; I don't know the exact context, so I don't know if it will work for you or not.

sichinumi
  • 1,835
  • 3
  • 21
  • 40