0

I've just noticed that that there is a difference in result when searching for a list item with CAML Query and getting it by ID.

Following piece of code returns item with 100 FieldValues:

var item = sourceList.GetItemById(1);
ctx.Load(item);
await ctx.ExecuteQueryRetryAsync();

While the following piece returns only 97 FieldValues:

var queryTxt = $"<View><Query><Where><Eq><FieldRef Name=\"ID\" /><Value Type=\"Integer\">1</Value></Eq></Where></Query></View>";
var query = new CamlQuery()
        {
            ViewXml = queryTxt
        };
var itemList = sourceList.GetItems(query);
ctx.Load(itemList);
await ctx.ExecuteQueryRetryAsync();
var item = itemsList.FirstOrDefault();

Is there anything I've missed?

Edit: If I invoke it like this, I also get 100 FieldValues

var queryTxt = $"<View><Query><Where><Eq><FieldRef Name=\"ID\" /><Value Type=\"Integer\">1</Value></Eq></Where></Query></View>";
var query = new CamlQuery()
    {
        ViewXml = queryTxt
    };
var itemList = sourceList.GetItems(query);
ctx.Load(itemList);
await ctx.ExecuteQueryRetryAsync();
var item = itemsList.FirstOrDefault();
ctx.Load(item);
await ctx.ExecuteQueryRetryAsync();
  • Do you have exactly 100 fields in your list, or are both of these getting you less than all columns? Can you do a compare between the result sets and see which three columns are missing from the camlQuery results? The types of the columns or the data present may give us a clue as to what is happening. – willman Jan 18 at 21:43
  • Not sure how many fields are there exactly and not really able to check it right now but (no access) but the missing field was a Person field. – Ciamas Jan 20 at 12:11
  • If there are specific fields you need from that set of 100-or-so, you may be better off specifying ViewFields in your CAML to get exactly the fields you need. With that many columns available, if you only need a handful of them, you're pulling down a much larger payload than you need. Plus, if you can figure out exactly which three were missing, you could specify those three in ViewFields to see if they still fail to be retrieved when explicitly requested. – willman Jan 20 at 12:30
  • The problem is that this is happening inside our "CopyListItem" function which is used to copy all the values of all "custom" fields. As the method is being used globally to duplicate items between sites and lists I am not able to predefine the fields. – Ciamas Jan 20 at 12:51
  • A few years ago, I had a similar issue on a server-side api CAML query was excluding all taxonomy fields for some unknown reason. Technically, we didn't solve the issue, do much as worked around it. We changed our query to only return the ID field to keep the query result as small and quick as possible, then did a GetItemById on the returned value. Creates a double lookup, but when the problem is inside the api, sometimes you have to code around the bug. – willman Jan 20 at 13:57
0

It should return the same FieldValues count for the item returned from CAML or getting by Id, here is the test capture in my side:

Get List Item (Id:1) with CAML, return 63 FieldValues when tracing:

enter image description here

Get List Item By Id directly, the FieldValues is the same 63:

enter image description here

  • Yes, from my experience it should return the same number of fields. However when checking this in debug it is not the case and there is a difference. – Ciamas Jan 20 at 12:55
  • Can you create a new list and then check to see if you can get the same fieldValues count ? – Jerry_MSFT Jan 20 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.