Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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('');
    }
   }    
});
share|improve this question

1 Answer 1

up vote 4 down vote accepted
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'

share|improve this answer
    
Thank u.. It worked :D –  luanna.iozzi Aug 25 at 13:44
    
Glad to hear that! –  Robert Lindgren Aug 25 at 13:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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