.find() where a lookup column is null or undefined

Aug 8, 2011 at 6:33 PM

I am trying to query a list to find all of the list items where a lookup field doesn't have a value. I am trying this from the xData return on a GetListItems method.

Here's the data:
Title :: Waldman    Parent :: undefined
Title :: Swanger    Parent :: 3;#Waldman
Title :: Adams    Parent :: 3;#Waldman
Title :: Haddad    Parent :: 3;#Waldman
When I use the jQuery .find() method with the following selector criteria, here are my results.
.find() code:
$(xData.responseXML).find([CRITERIA BELOW]).size()
results for criteria:
[nodeName=z:row] = 4
[nodeName=z:row][ows_Parent='3;#Waldman'] = 3
[nodeName=z:row][ows_Parent='null'] = 0
Does anyone know how to include an undefined field in my selector criteria?
An added note:  If I return all items and then test the parent field like such:
   ... do something
it works.  So, javascript recognizes the field as as having a null value. I just can't figure out how to "query" for it.
Aug 8, 2011 at 7:27 PM
Remember that all data returned in XML is text. When you are displaying things, it's the JavaScript kicking in when you see null or undefined.

This should work:
because the value of the Parent column is simply an empty string.

Note the 's around z:row, which is required in jQuery 1.5+. (I think that was when they began to enforce the requirement.)

Aug 8, 2011 at 9:00 PM

When I look at the raw data, the ows_Parent field isn't even present in the list item that doesn't contain a Parent.  So, maybe that is why I can't check for it.   The ows_Parent='' didn't work.

What I decided to do is to iterate through all of the rows and then test for ows_Parent===null.  That seems to work.



Aug 8, 2011 at 10:46 PM
Sorry I led you astray. I typed my answer from memory while sitting on the beach. :-)

You can also filter in the CAML for GetListItems so that you only get the items you actually want. That will be the most efficient.

Aug 8, 2011 at 11:05 PM

Rough life Marc!

I need all of the list items, I was just trying to select the node (in the xml doc) that had a null Parent attribute.  I'm using Lists and spservices to create an org chart using Google's chart API.  When I get everything working, I'll write it all up.

Thanks for your help and enjoy the beach!