I'm using the following query :

        camlQuery.set_viewXml = "<View><Query><Where><Eq><FieldRef Name='Employee'/><Value Type='User'>" + currentUser.get_title() + "</Value></Eq></Where></Query></View>";
      var listItemCollection = list.getItems(camlQuery);


    clientContext.executeQueryAsync(function () {

        var listItemEnumerator = listItemCollection.getEnumerator();

        if (listItemCollection.get_count() == 1 && listItemEnumerator.moveNext()) {

This query returns ok results (count = 1) using the U2U Caml Query builder. When i use the code in visual studio it returns 2 results, all the items in the list.

What is wrong with my code?

I also tried query with ID but again returns all items.

        //camlQuery.set_viewXml = ("<Query><Where><Eq><FieldRef Name='Employee' LookupId='True'/><Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value></Eq></Where></Query>");

1 Answer 1


Found the issue :

Problem is using camlQuery.set_ViewXml with hardcoded the query.

If i use this it works :

var ViewXml = "<View><Query><Where><Eq><FieldRef Name='Employee' LookupId='True'/><Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value></Eq></Where></Query></View>";

    //var ViewXml = "<View><Query><Where><Eq><FieldRef Name='Employee' LookupId='True'/<Value Type='Lookup'>" + currentUser.get_title() + "</Value></Eq></Where></Query></View>";

  • The main reason is you were missing ( and ) brackets around the caml query (refer your question). Just update the line and it will work. No need to write two seperate lines. Try Below line, it will also work -- camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='Employee'/><Value Type='User'>" + currentUser.get_title() + "</Value></Eq></Where></Query></View>"); Nov 10, 2017 at 12:30

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.