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>