0

I have a work from my time to use jQuery with SharePoint . I have written the code to get list items. When I run in IE it doesn't show any errors to me, but I am not getting the results. Can any one help me find a problem in the below code?

               var i=BANKID;
           $().SPServices({
                 operation:"GetListItems",
                 listName:"Test",
                 async:false,
                 CAMLViewFields: "<ViewFields>"+
                                 "<FieldRef Name='ID'/>"+
                                 "<FieldRef Name='A' />"+
                                 "<ViewFields>",
                 CAMLQuery:"<Query><Where><And><Eq><FieldRef Name='ID'/><Value Type='Counter'>"+1+"</Value></Eq></And></Where></Query>",
                               completefunc:function(xData,status)
                               {
                                  $(xData.responseXML).find("z:\\row").each(function()
                                     {
                                       var duid=$(this).attr("CustomerID");
                                       var questionis=$(this).attr("BANKID");

                                       $("#ctl00_m_g_d828bdd4_9329_4f8b_a18c_e9a26c43411a_ff5_1").val(duid);
                                       $("#ctl00_m_g_d828bdd4_9329_4f8b_a18c_e9a26c43411a_ff1_1").val(questionis);                          
                                   });

                              }

         });  

5 Answers 5

3

The same James mentioned plus the ViewFields tag is not closed. I recommend you to use Firebug on Firefox to play with the Sharepoint webservice changing the code until you get the expected results or use Fiddler to find out what's the webservice sending back.

2

You have a redundant AND clause in your CAML query.

Also, your code looks for CustomerID and BANKID in the results but you never request those fields in the ViewFields section.

0
1

The best way to go about this is to start with the basic call so that you get results. In other words, remove any filters, etc. just to be sure that you can get results from the list. Use alert(xData.responseText) to see what is returned from the call

Then add your filters back in one at a time (CAMLQuery, CAMLViewFields), making sure that each is doing what you want..

You should change from the "z:\row" notation to "[nodename='z:row']" as I show in the SPServices docs for cross browser compatibility.

0

Hi David Thanks for being there,David after your careful view and reply to me ,I removed view-fields.A I tried the sample code to get the value form list item based on ID of a list.But i don't know why i am not able to access list item values.I used alert message var i=$(this).attr('A'); alert(i); .I don't know why i am not able to get the value.alert(i) shows me message as undefined value.Hope you will respond to e David and James


     var query = "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>" + 2 + "</Value></Eq></Where></Query>";


          $().SPServices
          ({
             operation:"GetListItems",
             listName:"Test", 
             async:false, 

                CAMLQuery:query, 
                completefunc: function(xData, status)
                     {
                       $(xData.responseXML).find("z\\:row").each(function()
                         {
                            var i=$(this).attr('A');
                            alert(i);
                          });
                     }

              });  
2
  • What do you expect the A attribute to return for your item?
    – James Love
    Commented Oct 22, 2011 at 11:56
  • The attribute value should be a column from your sharepoint list, is there a column called 'A'?. Try for example: var i=$(this).attr('ows_Created'); alert(i); There is a default "Created" column in each list and that should work for you.
    – David Aleu
    Commented Oct 24, 2011 at 8:18
0

Can you please Change the value type to "Counter" in Caml query:

The query is like:

var query = "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + 2 + "</Value></Eq></Where></Query>";

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.