none
Microsoft JScript runtime error: Object doesn't support this property or method

    Question

  • Hi,

    I'm trying to use the SharePoint Object Model to retrieve info from a SharePoint List. After searching for some examples, I came up with the following code:

    var site;
    var context;
    var list;
    var collListItem;
    
    function Initialize() {
        var context = new SP.ClientContext.get_current();
    
        this.site = context.get_web();
        context.load(site);
    
        this.list = site.get_lists().getByTitle('MyList');
        context.load(list);
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml('\<View\>\<Query\>\<Where\>\<IsNotNull\>\<FieldRef Name=\'Title\' \/\>\<\/IsNotNull\>\<\/Where\>\<\/Query\>\<\/View\>');
        context.load(camlQuery);
        this.collListItem = list.getItems(camlQuery);
    
        context.load(collListItem);
    
        context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    
        typeResulsts(collListItem, "Title");
      }
    

    I get the Microsoft JScript runtime error: Object doesn't support this property or method when I call Initialize(). I believe the problem is related to the CAML Query, as commenting that part of the code eliminates the error. Does anyone have any idea as to the root of the problem?

    Wednesday, June 16, 2010 3:37 PM

Answers

  • Hi,

    The above code seems to be working after few modifications. Just make a note of the highlighted lines  below & try back in your code. Share your results.

    Note:  context.load(camlQuery);   (This line is not valid. That's reason you are getting error)

    function Initialize() {
          
            var site;
            var context;
            var list;
            var collListItem;
           
            context = new SP.ClientContext.get_current();
            site = context.get_web();
            context.load(site);

            list = site.get_lists().getByTitle('MyList');
            context.load(list);
         
            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml('<View><Query><Where><IsNotNull><FieldRef Name="Title" /></IsNotNull></Where></Query></View>');
            collListItem = list.getItems(camlQuery);
            context.load(collListItem);


            context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
           
          
        }

        function onQuerySucceeded(sender, args) {

            alert("Request succeeded. " + args.Message + "\n" + args.StackTrace);
        }

        function onQueryFailed(sender, args) {

          alert("Request failed. " + args.Message + "\n" + args.StackTrace);

        }

       
        _spBodyOnLoadFunctionNames.push("Initialize()");

     

    • Marked as answer by MSerejo Friday, June 18, 2010 8:48 AM
    Thursday, June 17, 2010 8:32 PM

All replies

  • Hi,

    The above code seems to be working after few modifications. Just make a note of the highlighted lines  below & try back in your code. Share your results.

    Note:  context.load(camlQuery);   (This line is not valid. That's reason you are getting error)

    function Initialize() {
          
            var site;
            var context;
            var list;
            var collListItem;
           
            context = new SP.ClientContext.get_current();
            site = context.get_web();
            context.load(site);

            list = site.get_lists().getByTitle('MyList');
            context.load(list);
         
            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml('<View><Query><Where><IsNotNull><FieldRef Name="Title" /></IsNotNull></Where></Query></View>');
            collListItem = list.getItems(camlQuery);
            context.load(collListItem);


            context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
           
          
        }

        function onQuerySucceeded(sender, args) {

            alert("Request succeeded. " + args.Message + "\n" + args.StackTrace);
        }

        function onQueryFailed(sender, args) {

          alert("Request failed. " + args.Message + "\n" + args.StackTrace);

        }

       
        _spBodyOnLoadFunctionNames.push("Initialize()");

     

    • Marked as answer by MSerejo Friday, June 18, 2010 8:48 AM
    Thursday, June 17, 2010 8:32 PM
  • Thanks Anjali. I ended up retrieving the lists through ASP.NET instead, but knowing why it wasn't working is great :)
    Friday, June 18, 2010 8:48 AM