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 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 dosen'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);                          
                                   });

                              }

         });  
share|improve this question

5 Answers 5

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>";
share|improve this answer

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.

share|improve this answer

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);
                          });
                     }

              });  
share|improve this answer
    
What do you expect the A attribute to return for your item? –  James Love Oct 22 '11 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 Oct 24 '11 at 8:18

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.

share|improve this answer

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.

share|improve this answer

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.