title: SharePoint Client Object Model - How to read a list with the same name in multiple sites
body: <p>My problem is the following:</p>
  
  <p>I have a list under the site collection root representing projects called 'Project Register'. Each item in that list represents a project where I am storing the project name, status, URL and some other properties. The URL is stored because each item will have a corresponding SharePoint sub site under the same site collection that is created dynamically via a custom event receiver created in Visual Studio.</p>
  
  <p>Each project sub site has a list called 'Members' used to keep track of the people that is assigned to that project. This is a business requirement and this list is used for some other purposes outside the scope of this question.</p>
  
  <p>Now, my challenge is that I need to show in a dropdownlist of another list called 'Timesheet' the projects in which the logged user has been assigned to. This is to give the user the capabilities to enter the time spent in those projects. This timesheet list is nothing but an out-of-the-box SharePoint calendar list with some custom fields.</p>
  
  <p>Below is the code I'm using but it keeps giving me the following error when retrieving the members list.</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot call method 'apply' of undefined</p>
  </blockquote>
  
  <p>Could anyone point me out in the right direction?</p>
  
  <p>The code I am using is in a custom .js file that I have properly referenced in my master page:</p>
  
  <pre><code> $(document).ready(function () {
  
      SP.SOD.executeOrDelayUntilScriptLoaded(loadMyProjects,'SP.js');
  
   });
  
      var $ddlMyProjectsNewItem;
      var allProjects = new Array();
  
      function loadMyProjects()
      {
  
      $ddlMyProjectsNewItem = $("#ctl00_ctl32_g_03acc13b_954d_4bdc_9544_b379206bc9d5_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_Lookup");
      var isTimesheetNewForm = $ddlMyProjectsNewItem.attr("id") != undefined ? true : false;
  
      if(!isTimesheetNewForm)
      {
          return;
      }
  
      $ddlMyProjectsNewItem.empty();
  
  
      // Get the current client context.
      var clientContext = SP.ClientContext.get_current();
      var web = clientContext.get_web();
  
      var list = web.get_lists().getByTitle('Project Register'); 
      var camlQuery = new SP.CamlQuery();
  
     camlQuery.set_viewXml("&lt;View&gt;" +
     "&lt;ViewFields&gt;" +
          "&lt;FieldRef Name='Full_x0020_Project_x0020_Name' /&gt;" +
          "&lt;FieldRef Name='ID' /&gt;" +
          "&lt;FieldRef Name='Links' /&gt;" +
      "&lt;/ViewFields&gt;" +
      "&lt;Query&gt;" +
          "&lt;Where&gt;" +
              "&lt;Eq&gt;" +
                  "&lt;FieldRef Name='Status' /&gt;" +
                  "&lt;Value Type='Lookup'&gt;WIP&lt;/Value&gt;" +
              "&lt;/Eq&gt;" +
         "&lt;/Where&gt;"+
          "&lt;OrderBy&gt;" +
              "&lt;FieldRef Name='Full_x0020_Project_x0020_Name' Ascending='FALSE' /&gt;" +
          "&lt;/OrderBy&gt;" + 
      "&lt;/Query&gt;" +
      "&lt;/View&gt;");
  
      this.collListItem = list.getItems(camlQuery);
  
      clientContext.load(collListItem);
  
      clientContext.executeQueryAsync(Function.createDelegate(this, this.onProjectsQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        
  
  }
  
  function onProjectsQuerySucceeded(sender, args) {
  
      var listItemEnumerator = collListItem.getEnumerator();
  
      while (listItemEnumerator.moveNext()) {
  
          var oListItem = listItemEnumerator.get_current();
          var projectId = oListItem.get_id();
          var projectName = oListItem.get_item('Full_x0020_Project_x0020_Name');
          var projectUrl = oListItem.get_item('Links');
  
          allProjects.push(projectId + "|" + projectName  + "|" + projectUrl);
      }
  
      $.each( allProjects, function( key, value ) {
  
          var projectMembers = new ProjectSiteMembers(value);
          projectMembers.get_members();
  
      });  
  
  }
  
  function ProjectSiteMembers(projectData) {
     // console.log(projectData);
  
      var projectValues = projectData.split('|');
      this.projectId = projectValues[0];
      this.projectName = projectValues[1];
      this.projectUrl = projectValues[2];
  
      this.clientContext = null;
      this.website = null;
      this.membersList = null;
      this.collListItemMembers = null;    
  }
  
  // Define the class methods.
  ProjectSiteMembers.prototype = {
      get_members: function () {
  
          //console.log(this.projectUrl);
  
          this.clientContext = new SP.ClientContext(this.projectUrl);
          this.website = this.clientContext.get_web();
  
          this.membersList = this.clientContext.get_web().get_lists().getByTitle('Members')
  
  
          var camlQuery = new SP.CamlQuery();
          camlQuery.set_viewXml("&lt;View&gt;" +
     "&lt;ViewFields&gt;" +
          "&lt;FieldRef Name='Member' /&gt;" +
      "&lt;/ViewFields&gt;" +
      "&lt;Query&gt;" +
          "&lt;Where&gt;" +
              "&lt;Eq&gt;" +
                  "&lt;FieldRef Name='Member' /&gt;" +
                  "&lt;Value Type='Integer'&gt;" +
                      "&lt;UserID Type='Integer' /&gt;" +
           "      &lt;/Value&gt;" +
              "&lt;/Eq&gt;" +
          "&lt;/Where&gt;"+
      "&lt;/Query&gt;" +
      "&lt;/View&gt;");
  
          this.collListItemMembers = this.membersList.getItems(camlQuery);
  
          this.clientContext.load(this.collListItemMembers);
  
              // Everything works until this point
              // This is the line giving me the error
          this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onProjectMembersQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));           
      }
  };
  
  
  function onProjectMembersQuerySucceeded(sender, args) {
  
      //console.log(this.projectId + " - " + this.projectName);
  
      var listItemInfoMember = '';
  
      var listItemMemberEnumerator = collListItemMembers.getEnumerator();
  
      while (listItemMemberEnumerator.moveNext()) {
          var oListItemMember = listItemMemberEnumerator.get_current();
  
  
              $ddlMyProjectsNewItem 
                  .append('&lt;option value="' + this.projectId + '"&gt;' + this.projectName + '&lt;/option&gt;');
  
      }        
  }
  
  function onQueryFailed(sender, args) {
  
      alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  }
  </code></pre>