4

When I try to run my javascript SP.JS file in a user control I get this error: Microsoft JScript runtime error: Unable to get value of the property 'isNullOrUndefined': object is null or undefined

The complete code is the following (Just copied it over from a book).

<script type="text/javascript" src="/_layouts/MicrosoftAjax.js" ></script>
<script type="text/javascript" src="/_layouts/SP.js" ></script>
<script language="javascript" type="text/javascript">

    ExecuteOrDelayUntilScriptLoaded(GetTitle, "sp.js");
    var site;
    var context;

    function GetTitle() {
        context = SP.ClientContext.get_current();

        site = context.get_web();
        context.load(site);

        context.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    }
    function onQueryFailed(sender, args) {
        alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    function onQuerySucceeded(sender, args) {
        document.getElementById("Text1").value = site.get_title();
    }
    function Button1_onclick() {
        site.set_title(document.getElementById("Text1").value);
        site.update();

        context.load(site);

        context.executeQueryAsync(onTitleUpdate, onQueryFailed);
    }
    function onTitleUpdate(sender, args) {

    }

The function where the error occurs is...

SP.ClientContext.initializeBase(this,[SP.ScriptUtility.isNullOrUndefined(a)?SP.PageContextInfo.get_webServerRelativeUrl():a])};

0

2 Answers 2

3
<script type="text/ecmascript" src="/_layouts/SP.Core.JS"></script>

One of my friend tried to resolve a similar problem by adding the above line, you might be using a custom master page so the reference is missing (should be present in the standard master page).

5
  • This doesn't look like an answer to the question. Could you improve that a little?
    – Benny Skogberg
    Commented Apr 9, 2013 at 9:44
  • 1
    Script mark-up was hidden. I have edited so the answer makes more sense now.
    – SPDoctor
    Commented Apr 10, 2013 at 10:27
  • @SPDoctor - now I understand what he was meaning. Note to self - next time an answer does not make sense, try to edit it and see if it is missing a piece. Commented Apr 10, 2013 at 11:32
  • (also +1 since now I understand the answer) Commented Apr 10, 2013 at 11:38
  • @SPArchaeologist ... and note to posters - check the rendered view looks okay before posting :-)
    – SPDoctor
    Commented Apr 10, 2013 at 13:19
5

This is what I used to fix this problem:

<SharePoint:ScriptLink Name="MicrosoftAjax.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.js" runat="server" Defer="True" Localizable="false"/>

I added the above ScriptLinks in this order, and defered both the MicrosoftAjax.js and SP.Core.js includes, and delayed the SP.js. The SP.js file has dependencies in the preceding includes that requires it to be delayed.

2
  • it resolved "sp.scriptutility is null" error
    – Iman
    Commented Aug 6, 2016 at 11:07
  • it also resolved "Undefined in SP.UI.ModalDialog.showModalDialog" error
    – Iman
    Commented Aug 6, 2016 at 11:08

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.