Problem using getSPItemsWithQuery

Aug 31, 2010 at 1:07 AM

Hi, I'm trying to use getSPItemsWithQuery, but does not filter and I get all the items in the list, but I just want to get one according to a filter.

I'm using something like this:

  var item = "IP";

  var tipo = "lookup";

 var valor= 999;

  var objetoLista = jP.Lists.setSPObject(direccionURL,nombreLista);
  var query = "<Query><where><Eq><FieldRef Name='"+item+"' /><Value Type='"+tipo+"'>"+valor+"</Value></Eq></where></Query>";
 
  objetoLista.getSPItemsWithQuery(query);

 

Hopefully someone can help me out

Regards

Coordinator
Sep 7, 2010 at 2:57 PM

Try this

To retrieve by lookup id:

var item = "State";
var tipo = "Lookup";
var valor= 5;
var query = "<Where><Eq><FieldRef Name='"+item+"' LookupId='True' /><Value Type='"+tipo+"'>"+valor+"</Value></Eq></Where>";

var list = jP.Lists.setSPObject("/site/test", "LookupList2");
list.getSPItemsWithQuery(query);

To retrieve by lookup value:

var item = "State";
var tipo = "Lookup";
var valor= "Colorado";
var query = "<Where><Eq><FieldRef Name='"+item+"' /><Value Type='"+tipo+"'>"+valor+"</Value></Eq></Where>";

var list = jP.Lists.setSPObject("/site/test", "LookupList2");
list.getSPItemsWithQuery(query);

Sep 9, 2010 at 3:34 PM

It doesn't work.

For example: I have one list called list1 with two fields

list1

city                        Country_lookupfields

New York                        1

Chicago                          1

Texas                               1

Boston                            1

Buenos Aires                  2

Santiago                         3

Viña del Mar                  3


var item = "
Country_lookupfields";
var tipo = "Lookup";
var valor = 1;
var
query = "<Where><Eq><FieldRef Name='"+item+"' LookupId='True' /><Value Type='"+tipo+"'>"+valor+"</Value></Eq></Where>";
var
list = jP.Lists.setSPObject("/site/test", "list1");
list.getSPItemsWithQuery(query);

I should obtain only 4 rows (New York, Chicago, Texas and Boston), but I get all rows from the list.

what can I do?

Regards.
Coordinator
Sep 13, 2010 at 3:29 PM

Take at look at this example

http://www.sharejpoint.com/examples/src/Example_LookupList1.aspx

login name = demouser

password = sharejPoint!

 

What type of field is Country_lookupfields?  Set the Value Type appropriately.  Also is your list on the root site or subsite?