How can I determine if a ListItem field already has a value? #1229
-
This sounds simple and should be easy but for whatever reason SharePoint is a pain and any help would be appreciated. I'm trying to populate the
Maybe it has something to do with how I am loading the item? I've tried setting up my query to include fields like in the doc example but that didn't change anything. I also should mention later in my code I am able to assign to that field and see the value reflected in SP UI so I know it is a valid field. I just can't get the existing value. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I've tried these variations too but they also produce errors or false: // KeyNotFoundException
var hasProjectNumber = item["ProjectNumber"] != null;
// Always false
var hasProjectNumber = item.File.ListItemAllFields.Values.ContainsKey("ProjectNumber")
|| item.Folder.ListItemAllFields.Values.ContainsKey("ProjectNumber"); |
Beta Was this translation helpful? Give feedback.
Thanks Bert but it looks like the only way I was able to get the properties to load was by using the All property when loading the item:
It didn't load it with any other combination of properties I tried to load. Not sure if that is a bug or just the way the API works but feels hacky. I also tried
li => li.Values
but that produces an error.