1

I have the following code and it does not work. Apparently it's all right. The List name and the URL.

Can anyone help me find the syntax error?

PS: I use Sharepoint Foundation 2010

$().SPServices({
  operation: 'GetListItems',
  async: false,
  listName: 'MyList_Name',
  webURL: 'http://domain.com/', 
  CAMLViewFields: '<ViewFields>'+
                    '<FieldRef Name="NamePage" />'+
                    '<FieldRef Name="Date" />'+
                    '<FieldRef Name="Title" />'+
                '<ViewFields>',
  CAMLQuery: "<Query><OrderBy><FieldRef Name='Date' Ascending='FALSE'></OrderBy></Query>",
  completefunc: function (xData, Status){

    htmlReturn += '<div class="coluns">';

    $(xData.responseXML).SPFilterNode('z:row').each(function() {
        var Title = $(this).attr('ows_Title'),
            Date = $(this).attr('ows_Date'),
            NamePage = $(this).attr('ows_NamePage');

        if(aux <= 6){
            htmlReturn +=  '<ul>'+
                                '<li class="date">'+Date+'</li>'+
                                '<li><a href="'+NamePage+'.aspx">'+Title+'</a></li>'+
                            '</ul>';
            aux++;
        }
    });
    htmlReturn+= '</div>';

    if(htmlReturn != ''){
        $('.Result').html(htmlReturn);
    }else{
        $('.Result').html('');
    }
   }    
});
4
CAMLViewFields: '<ViewFields>'+
                '<FieldRef Name="NamePage" />'+
                '<FieldRef Name="Date" />'+
                '<FieldRef Name="Title" />'+
            '<ViewFields>'

should be

CAMLViewFields: '<ViewFields>'+
                '<FieldRef Name="NamePage" />'+
                '<FieldRef Name="Date" />'+
                '<FieldRef Name="Title" />'+
            '</ViewFields>'

note the /on the last ViewFields

Also, this

"<Query><OrderBy><FieldRef Name='Date' Ascending='FALSE'></OrderBy></Query>",

should be

"<Query><OrderBy><FieldRef Name='Date' Ascending='FALSE' /></OrderBy></Query>",

note the / after Ascending='FALSE'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.