0

I am using C#.Net to query Sharepoint site. I am able to return all the data I need except ONE field, which the culprit seems to be due to it is a calculated field so it does not "exist" in my query results.
I have calculated field called hours worked, how can I query that field and return the results in my below syntax?

This is how I query:

string server = "blahblahblah";
string msn = "14318";
var ctx = new ClientContext(server);
ver web = ctx.Web;
List list = web.Lists.GetByTitle("Attendance");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<where><Eq><FieldRef Name='EmployeeID' /><Value Type='Text'>"+msn+"</Value></Eq><Where>";
var listItemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());

ctx.Load(listItemCollection, eachItem => eachItem.Include(
                                          item => item,
                                          item => item["recID"],
                                          item => item["MasterID"]));
ctx.ExecuteQuery();

foreach (ListItem li in listItemCollection)
{
    Console.WriteLine(li["recID"]);
    Console.WriteLine(li["MasterID"]);
}

1 Answer 1

1

there's a huge error in your code

var listItemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());

that should be

var listItemCollection = list.GetItems(camlQuery);

it is really possible the "createallitems" won't contain and might remove calculated columns as those are not required for item creation, i would also add the fields to the View portion of the CamlQuery

to add fields to the camlquery

<ViewFields>
<FieldRef Name="Field1"/>
<FieldRef Name="Field2"/>
<FieldRef Name="Field3"/>
</ViewFields>
11
  • Interesting. My syntax executed as expected even with my incorrect code. Any idea how to pull the data from the calculated field? Commented Mar 15, 2018 at 21:01
  • edited to add the reason
    – Mike
    Commented Mar 15, 2018 at 21:03
  • Would I use single quotes to encompass the field names? Commented Mar 15, 2018 at 21:09
  • you can use both single quotes or \"
    – Mike
    Commented Mar 15, 2018 at 21:10
  • It has been sitting on my ctx.ExecuteQuery() for 2 minutes now? I set query to camlQuery.ViewXml = "<ViewFields><FieldRef Name="Field1"/><FieldRef Name="Field2"/><FieldRef Name="Field3"/> </ViewFields><where><Eq><FieldRef Name='EmployeeID' /><Value Type='Text'>"+msn+"</Value></Eq><Where>"; Commented Mar 15, 2018 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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