The code below is working fine in my dev machine but the moment I tried to test it on our customer's server, I started getting errors.

I started having errors with SP.js. So I used the

<script type="text/javascript" src="/_layouts/15/SP.Core.js"></script>
<script type="text/javascript" src="/_layouts/15/SP.Runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/SP.Search.js"></script>

<script type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext',function(){

    var queryText = "ContentTypeId:0x010066FA3DE3E334C841B418C82CC475A227*";
            var clientContext = new SP.ClientContext.get_current(); 
            var contextSite = clientContext.get_site();
            var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext); 

            var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);  
            var results = searchExecutor.executeQuery(keywordQuery); 
            clientContext.executeQueryAsync(onQuerySuccess, onQueryError);

            function onQuerySuccess()
                var message = $("#message");
                message.text("Search results fro \"" + queryText + "\"");
                message.append("<br />");
                var rows = results.m_value.ResultTables[0].ResultRows;
                $.each(rows, function(index, value)
                    message.append(value.Title + ": " + value.Path);
                    message.append("<br />");


but now I am getting this error: Unable to get property 'ResultRows' of undefined or null reference.

Any idea how to solve this?

2 Answers 2


I think you have the client context that starts with dev and you are in test:

var clientContext = new SP.ClientContext("http://dev");
  • Sorry for the confusion, but I have changed it already to this: var clientContext = new SP.ClientContext.get_current();
    – Imir Hoxha
    Commented Aug 27, 2015 at 14:20
  • The code looks ok, are you sure the content type is present in the new environment? Query is executing ok but returning 0 results.
    – Xavi
    Commented Aug 28, 2015 at 6:45

Try swapping that to

$.each(results.m_value.ResultTables[0].ResultRows, function () {
   //... Stuff you want to do 

Also, I wonder if your results is out of scope, try removing the var away from the front of the first declaration, and then in the resulting reference to results, use this.results,

so from:

var results = searchExecutor.executeQuery(keywordQuery); 


results = searchExecutor.executeQuery(keywordQuery); 

and then to access:

var rows = this.results.m_value.ResultTables[0].ResultRows;


$.each(this.results.m_value.ResultTables[0].ResultRows, function () {
  // ... stuff you want to do

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.