I have a view form in a list. I want to add a dropdown and populate that dropdown from Another list, so I added a scripteditor in my viewform and added the code below. I can get my code to run when I have the page in edit mode, but not when I open the form.

I've tried to disable the "Minimal download strategy"

I get an errormessage in the browsers debugger when I run the code normally:

Error: Unable to get property 'isNullOrUndefined' of undefined or null reference in sp.js file.


<button class="ms-Button ms-Button--hero"> <span class="ms-Button-icon"><i class="ms-Icon ms-Icon--plus"></i></span> <span class="ms-Button-label">Add Role</span> <span class="ms-Button-description">Adds a role to this service</span> </button>
<select id="rolesSelect"></select>
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(retrieveCurrentListProperties, "SP.js");
function retrieveCurrentListProperties() { 

var clientContext = new SP.ClientContext("/sites/documentation");
var oList = clientContext.get_web().get_lists().getByTitle("Roles");
var camlQuery = new SP.CamlQuery();
this.collListItem = oList.getItems(camlQuery);
clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
function onQuerySucceeded()
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
$("#rolesSelect").append('<option value=""></option>');    
while (listItemEnumerator.moveNext()) 
    var oListItem = listItemEnumerator.get_current();
    $("#rolesSelect").append('<option value="' + oListItem.get_item("Title") + '">'+ oListItem.get_item("Title") +' </option>'); 

function onQueryFailed(sender, args)
alert('Request failed. ' + args.get_message() + 
    '\n' + args.get_stackTrace());


What am I'm doing wrong??

1 Answer 1


You break everything with with this script-tag:

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

Remove this one and your script should work just fine

  • Amazing. Thank you very much. How come that? Is not that file very needed to make jsom model working? Jun 23, 2016 at 3:21
  • It is, but it is also already loaded with your masterpage. My guess is that running this script again at a later stage re-initializes the state of of a lot of objects etc wich have already been modified by other scripts that depend on sp.js, and that's not good. Jun 23, 2016 at 4:15

Your Answer

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

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