2

enter image description here

I want to get the list items where invoice _category is equal to "Service".

Please help?

Current code:

camelQuery.Viewxml = "<View><Query> <Where><Eq><FieldRef Name='Invoice_Category'/> <Value Type='Text'>Service</Value></Eq></Where><Query></View>"

It throws an error of string constant.

  • What is the data type of your column/field (invoice _category)? – Ganesh Sanap Feb 17 at 6:59
  • 1
    The last <Query> element should terminate the first one -- it is missing a forward slash... – Rune Sperre Feb 17 at 7:03
  • Yes, there are some syntax errors in CAML. refer below answer for complete query. – Ganesh Sanap Feb 17 at 7:07
0

Try to use your CAML in below format:

<View>
    <Query>
        <Where>
            <Eq>
                <FieldRef Name='Invoice_Category'/>
                <Value Type='Text'>Service</Value>
            </Eq>
        </Where>
    </Query>
</View>

Note:

  1. In CAML query you need to use internal name of your column/field.

    Find the internal name of SharePoint column

Complete Code:

string siteUrl = "http://tenant.sharepoint.com/sites/SiteName";  

ClientContext clientContext = new ClientContext(siteUrl);  
SP.List oList = clientContext.Web.Lists.GetByTitle("ListName");  

CamlQuery camlQuery = new CamlQuery();  
camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Invoice_Category'/><Value Type='Text'>Service</Value></Eq></Where></Query></View>";  

ListItemCollection collListItem = oList.GetItems(camlQuery);  

clientContext.Load(collListItem);  
clientContext.ExecuteQuery();  

foreach (ListItem oListItem in collListItem) {  
    Console.WriteLine("ID: {0} \nTitle: {1}", oListItem.Id, oListItem["Title"]);  
}  

Update from Comments:

Also, from the screenshot you attached in your question, I can see that the value in your column is "Service Invoice" and not just "Service". So in that case you might need to use Contains instead of Eq. check below query:

<View>
    <Query>
        <Where>
            <Contains>
                <FieldRef Name='Invoice_Category'/>
                <Value Type='Text'>Service</Value>
            </Contains>
        </Where>
    </Query>
</View>

Reference: Query schema.

  • options strics on disallows implicit conversions from system.xml.linq.xelement to string error is there – user89072 Feb 17 at 7:08
  • Try using the code given in my updated answer. let me know if this works for you. Or you can add the complete code you are using to get list items to your question. – Ganesh Sanap Feb 17 at 7:11
  • ',' expected error – user89072 Feb 17 at 7:15
  • actualy we have an invoice list in which to get the information of the service from the invoice category coloumn – user89072 Feb 17 at 7:18
  • At which code line you are getting this error? Also, what is the data type and internal name of your "Invoice_Category" column? Can you please add the screenshot of column settings for Invoice_Category column? (Go to list settings-->navigate to columns section-->click on the Invoice_Category column name-->take screenshot-->Edit your question-->attach image). – Ganesh Sanap Feb 17 at 7:24

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