Client Context undefined or null for Read Only User

Had a requirement to execute some JavaScript to get search results from SharePoint. During the implementation observed that SP.ClientContext was undefined, when a user having only Read Only permissions on the site was executing the script.

var context = new SP.ClientContext.get_current();

Solved it by adding the following script references before creating the context.

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

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

Also generated the context without the new keyword as follows:

var context = SP.ClientContext.get_current();

Comments are closed.