Search code examples
sharepointsplistitemspquery

Can I retrieve additional fields for a SPListItem from SPQuery which had ViewFields set?


I am retrieving SPListItems from SPList with a SPQuery that has ViewFields set. I am using ViewFields to improve performance. However, for some items, I need additional data. I know I can just retrieve the single item again with a new query. However, I am wondering, is there a more efficient way that would allow me to just pull the additional fields I need?


Solution

  • There is no way to specify that you only want a field included if certain criteria is meet. So Your options are:

    • Always get all the fields you need
    • Make Multiple queries. Here I'd suggest that you make one for items where you don't need ekstra fields and one for items where you need them instead of starting to do Per Item queries
    • If you're on the server use GetItemById to get full SPListItem's for your special items
    • Make a calculated field which is empty if criteria is not fulfilled and otherwise is a concatenation of your ekstra fields. You can the include this field in your general Query