I’m currently working with several different custom SharePoint lists. Some of the lists have references to other lists, via a “Lookup” column. For example, a book might have a reference back to the library it came from.
Sometimes I only know the name of the library, and I want to be able to set a reference to it on the book’s list. So I retrieve the library’s ID using the name of the library. SharePoint Designer dutifully warns me that I’m not looking up the value using a unique ID, and that it will just give me the first one it finds. I’m OK with that, since I control the names and I know that they’re all unique.
But I’m only human, and sometimes I don’t have a library name that exists in my library list.
In those cases, when I log the contents of the list ID variable into which I placed the data, it shows me “0”. [That’s the number zero, not to be confused with a lower-case “o”. I’m considering changing the font for this blog… -sj]
As it turns out, this is the way you can tell if you have a valid list ID. Valid IDs start at 1, I presume, and invalid IDs are all zero.
[It’s easy to tell if you have a bad reference to another list when you retrieve string values, since they show up in log messages as “????”.]