0

I am making a web part that will be added to a list page, and I need to access the selected items in the list. I am trying to do this using the following method (mentioned here: Get selected item in SharePoint list):

var context = SP.ClientContext.get_current();
var listId = SP.ListOperation.Selection.getSelectedList(); //get selected list Id
var selectedItemIds = SP.ListOperation.Selection.getSelectedItems(context); //get selected items

I initially included this code as part of a custom view, which worked well, however when running this as part of a web part I get the following error after calling the getSelectedList function:

Uncaught ReferenceError: GetCurrentCtx is not defined

I am assuming this change has to with the fact that the Web Part is running in an IFrame, but I am stuck as to how to get around this. Any help is greatly appreciated.

EDIT:

After adding core.js I now get the following error :

Uncaught ReferenceError: IsNullOrUndefined is not defined

These are all the js files I am including :

<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script>
<script type="text/javascript" src="/_layouts/15/core.js"></script>

1 Answer 1

1

This error occurs since GetCurrentCtx function is a part of core.js SharePoint library, it is intended for getting context info of XLV web part (ContextInfo object), so:

  • core.js library have to be loaded first
  • it could be executed only in the SharePoint page that contains the instance of XLV web part since ContextInfo object is generated when the XLV web part is rendered on page
1
  • Thanks for the response. I included core.js, but I now get "IsNullOrUndefined is not defined" when loading the page. Any ideas? Commented May 6, 2015 at 12:20

Your Answer

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

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