I have a button that runs a JS function (in a Script Editor Web Part):

function flexRegistration() {

    var context = SP.ClientContext.get_current();
    var listId = SP.ListOperation.Selection.getSelectedList();

However if I am not logged in, I get an error:

Uncaught TypeError: Cannot read property 'Selection' of undefined

How can I get this to run for anonymous users, or for a specific permissions level? (owners, Members, Visitors, or other)?

Here's the actual page: http://www.sd72.bc.ca/school/timberline/Programs/Flex/Pages/default.aspx

The button that triggers the function is there called "Register for Selected Events"

The list being read is the same one that is on display and is publicly readable (filter to Dec 16th to get events, though not necessary to see error)

  • 1
    I think you should turn on the Allow Anonymous User on your site.
    – dant
    Dec 15, 2015 at 4:08
  • Anonymous users can view. Dec 15, 2015 at 22:07
  • I found there is person meet the same trouble with you. Can you view this link Access ribbon ? I guess your permission need at least Manage Personal Views permission.
    – dant
    Dec 16, 2015 at 1:53
  • 1
    One more thing, your function flexRegistration will count items of both of Event list and Documents for Parents list. You should have condition if selected list is Event list or not.
    – dant
    Dec 16, 2015 at 2:10

1 Answer 1


It appears the JS library isn't loading for anonymous users, so ListOperation doesn't exist.

It can be loaded like this:

SP.SOD.executeFunc('SP.Core.js', 'SP.ListOperation', function () { 
    var listId = SP.ListOperation.Selection.getSelectedList();
    var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);

This resolved the error

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.