I want to match the current user with a lookup field in a specific list. It seems something is wrong with my caml query.

var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var list = web.get_lists().getByTitle("Managers");
    var currentUser = context.get_web().get_currentUser();
    var currentUserLoginName = currentUser.get_loginName();
    var currentUserId = currentUser.get_id();
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Employee\'LookupId=\'True\'>' +
        '<Value Type=\'Lookup\'>' + currentUserId + '</Value></Eq></Where></Query></View>');

    var listItemCollection = list.getItems(camlQuery);


Where is my mistake?

Thanks a lot !

  • what's the error you see? Oct 16, 2017 at 6:39
  • Actually there isn't any error . It just won't return any results although i have records with the lookup field value to current user
    – shak
    Oct 16, 2017 at 6:41

2 Answers 2


Try this code:

var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle("ListName");
var cQuery = new SP.CamlQuery();
var camlXML = "<View><Query><Where><Eq><FieldRef Name='Author' LookupId='True'/><Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value></Eq></Where></Query></View>";
var listitems = list.getItems(cQuery);
context.executeQueryAsync(function() {
        var enumerator = listitems.getEnumerator();
        while (enumerator.moveNext()) {
            var item = enumerator.get_current().get_fieldValues();
    function(s, a) {

To match current user you can directly use below CAML query :

    <FieldRef Name="Employee" />
    <Value Type="Integer">
      <UserID Type='Integer'/>

I have made some changes to your code. Refer below code. This should work :

function getData(){

    var clientContext = new SP.ClientContext.get_current();
    var list = clientContext.get_web().get_lists().getByTitle("Managers");
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='Employee' /><Value Type='Integer'><UserID Type='Integer'/></Value></Eq></Where></Query></View>");
    listItemCollection = list.getItems(camlQuery);

    clientContext.executeQueryAsync(getDataSuccess, getDataFailed);


function getDataSuccess(){

    var listItemEnumerator = listItemCollection.getEnumerator();
         var oListItem = listItemEnumerator.get_current();

         // further code 


function getDataFailed(sender, args){

    // failure handler


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.