Fixing bugs is the nicest thing to do!
The javascript exception was thrown by a page:
The value of the property ‘SearchEnsureSOD’ is null or undefined, not a Function object
by just clicking in the page…
Hmm, according to the name of the function it seemed it has something to do with search and after investigating the page it seemed there was a custom Coreresults webpart on the page when there was no searchbox on the same page…
To make sure this was it I added a searchbox to the masterpage and the javascript exception didn’t occur again.
No big deal, just checked the difference in script files loaded with the developer tools between the page where the error occurred and a page where the searchbox was present: search.js is missing.
After adding a reference to the search.js file in the masterpage another exception was thrown when the page loaded:
The value of the property ‘NotifyScriptLoadedAndExecuteWaitingJobs’ is null or undefined, not a Function object
Ok, this function is defined in init.js, which actually was loaded already…
Maybe init.js was loaded later than the function NotifyScriptLoadedAndExecuteWaitingJobs was called. Just to be sure a reference to init.js was added in the masterpage and the initial exception was thrown again:
The value of the property ‘SearchEnsureSOD’ is null or undefined, not a Function object
It seemed the function SearchEnsureSOD wasn’t loaded when the body (body element in masterpage) was loaded. By adding a function to the _spBodyOnLoadFunctionNames array, the onload eventhandler of the body will execute each function loaded in this array. So by adding the SearchEnsureSOD function to this array it will run when the onload event of the body fires.
To be very minimalistic and a lazy programmer I added an empty SearchEnsureSOD function to the _spBodyOnLoadFunctionNames array:
<script language="javascript" type="text/javascript"> function SearchEnsureSOD() { } _spBodyOnLoadFunctionNames.push('SearchEnsureSOD'); </script>
and the javascript error didn’t occur again.
So what about deleting the reference to search.js? That won’t work, because this is the statement the error occurs on:
$addHandler(window.document.documentElement, 'click', function(evt){SearchEnsureSOD();SearchNavigate(evt);});//]]>
and it uses the function SearchNavigate, which is actually defined in search.js
So the full code to add to the masterpage:
<SharePoint:ScriptLink name="init.js" runat="server"/> <SharePoint:ScriptLink name="/_layouts/search.js" runat="server"/> <script language="javascript" type="text/javascript"> function SearchEnsureSOD() { } _spBodyOnLoadFunctionNames.push('SearchEnsureSOD'); </script>
On a search result page the function is defined as:
function SearchEnsureSOD() { EnsureScript('search.js',typeof(GoSearch)); } _spBodyOnLoadFunctionNames.push('SearchEnsureSOD');
Where GoSearch is present when the searchbox control is.
Summary
The Coreresults webpart is a great thing, but it apparently needs some work when there is no searchbox present at the page. In this post the solution is provided to make it all work.
Hi, just wanted to thank you. your solution worked.
Thanks Anita, ran into the same here and it worked for us as well. Just hope it won’t interfere with out of the box functionality behind this function name on the longer run.