1

I cannot for the life of me figure out why I don't get the null or undefined error here, the input button is where I'm getting the error in F12 or firebug.......

<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"/>
<SharePoint:FormDigest ID="MyFormDigest" runat="server"/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<!-- Scripting -->
<script>
function OnLoad()
    { 
   alert("Test");
    }   // End OnLoad
</script>

<!-- HTML -->
<div>
<input name="Test_JavaScript" type="button" value="Press Here Dummy!" onclick="JavaScript:OnLoad()"/> <!-- The value of the property 'OnLoad' is null or undefined, not a Function object, I don't get the error for this snippet -->
</div>

but I get it with this code. Can anyone shed some light on this error for this javascript noob, I've researched this error for over a day now....

<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"/>
<SharePoint:FormDigest ID="MyFormDigest" runat="server"/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<!-- Scripting -->
<script>
function OnLoad()
{
        var siteUrl = '/sites/Test/subsite';
    ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
    function retrieveListItems() {


    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('CAML Query');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /><FieldRef Name='Status' /></ViewFields>');
    this.collListItem = oList.getItems(camlQuery);
    clientContext.load(collListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));       
    }

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nID: ' + oListItem.get_id() + '\nTitle: ' + oListItem.get_item('Title') + '\nStatus: ' + oListItem.get_item('Status');
        }
    alert(listItemInfo.toString());
    }

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
 }  // End OnLoad
</script>

<!-- HTML -->
<div>
<input name="Test_JavaScript" type="button" value="Press Here Dummy!" onclick="JavaScript:OnLoad()"/>   <!-- The value of the property 'OnLoad' is null or undefined, not a Function object -->
</div>

Thank you!

2 Answers 2

2

At first glance I would say you get the error "The value of the property is null or undefined, not a Function object" because the function OnLoad is not defined. At least it should not be, based on your code, because your code has errors in it.

To fix the error try changing camlQuery.set_viewXml('<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /><FieldRef Name='Status' /></ViewFields>'); into

camlQuery.set_viewXml("<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /><FieldRef Name='Status' /></ViewFields>");

Note ' vs " there.

1

See eirik's answer. Here's the slightly modified code (structure).

function OnLoad() {
    var siteUrl = '/sites/Test/subsite';

    ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");

    function retrieveListItems() {

        var clientContext = new SP.ClientContext(siteUrl);
        var oList = clientContext.get_web().get_lists().getByTitle('CAML Query');

        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml("<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /><FieldRef Name='Status' /></ViewFields>");
        collListItem = oList.getItems(camlQuery);
        clientContext.load(collListItem);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
} //End OnLoad

function onQuerySucceeded(sender, args) {
   var listItemInfo = '';
   var listItemEnumerator = collListItem.getEnumerator();

   while (listItemEnumerator.moveNext()) {
       var oListItem = listItemEnumerator.get_current();
       listItemInfo += '\nID: ' + oListItem.get_id() + '\nTitle: ' + oListItem.get_item('Title') + '\nStatus: ' + oListItem.get_item('Status');
    }

    alert(listItemInfo);
}

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

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.