title: Retrieve sharepoint List in javascript
body: <p>I would like retrieve the title of sharepoint List in JS.</p>
  
  <p>My function JS :</p>
  
  <pre><code>function retrieveAllListsAllFields() {
          var ctx = SP.ClientContext.get_current();
          var web = ctx.get_web();
          ctx.load(web, "Title");
  
      ctx.executeQueryAsync(
      Function.createDelegate(this, function(){
          var listTitle = web.get_title() + " Documents";
      }),
      Function.createDelegate(this, this.onQueryFailed)
      );
  </code></pre>
  
  <p>I retrieve the list but i would like use this list in another function for get the documents list of my library in a combo box :</p>
  
  <pre><code>function initComboBox(fileslistBox, fileslistBoxDest, selectLibraryFileFieldResult, entityComboBox, yearComboBox, typeComboBox, library, entityValue, currentSiteUrl) {
      function retrieveAllListsAllFields() {
          var ctx = SP.ClientContext.get_current();
          var web = ctx.get_web();
          ctx.load(web, "Title");
  
          ctx.executeQueryAsync(
          Function.createDelegate(this, function(){
              var listTitle = web.get_title() + " Documents";
          }),
          Function.createDelegate(this, this.onQueryFailed)
          );
  
      var listBox;
      var i = 0;
      var reggie = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
      var entityComboBoxArray = new Array();
      var yearComboBoxArray = new Array();
      var typeComboBoxArray = new Array();
  
      addItemToArray(entityComboBoxArray, "", "", i);
      addItemToArray(yearComboBoxArray, "", "", i);
      addItemToArray(typeComboBoxArray, "", "", i);
  
      //init all combox 
      $().SPServices({
          operation: "GetListItems",
          webURL: currentSiteUrl,
          async: true,
          listName: listTitle,        
          CAMLViewFields: "&lt;ViewFields&gt;&lt;FieldRef Name='ID' /&gt;&lt;FieldRef Name='FileLeafRef' /&gt;&lt;FieldRef Name='File_x0020_Type' /&gt;&lt;FieldRef Name='Title' /&gt;&lt;FieldRef Name='Entity' /&gt;&lt;FieldRef Name='Year_Document' /&gt;&lt;FieldRef Name='Library' /&gt;&lt;/ViewFields&gt;",
          CAMLQuery: "&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name='Title' /&gt;&lt;/OrderBy&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='Library' /&gt;&lt;Value Type='Choice'&gt;" + library + " &lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;",
          completefunc: function (xData, Status) {
              $(xData.responseXML).SPFilterNode("z:row").each(function () {
                  i++;
                  //Add value to combox Array
                  alert(listTitle);
                  var tmpEntity = $(this).attr("ows_Entity");
                  if (tmpEntity != null)
                      addItemToArray(entityComboBoxArray, $(this).attr("ows_Entity"), (tmpEntity).split("#")[1], i);
  
                  var tmpYear = $(this).attr("ows_Year_Document");
                  if (tmpYear != null)
                      addItemToArray(yearComboBoxArray, tmpYear, tmpYear, i);
  
                  var tmpType = $(this).attr("ows_File_x0020_Type");
                  if (tmpType != null)
                      addItemToArray(typeComboBoxArray, tmpType, tmpType, i);
  
                  //if option already in Result Select, we move it to the destination RadListBox
                  if (isOptionContainInSelect(selectLibraryFileFieldResult, $(this).attr("ows_Title")) == true)
                      listBox = fileslistBoxDest;
                  else listBox = fileslistBox;
                  addNewFilesItem($(this).attr("ows_ID"), $(this).attr("ows_FileLeafRef"), $(this).attr("ows_Title"), $(this).attr("ows_Entity"), $(this).attr("ows_Year_Document"), $(this).attr("ows_File_x0020_Type"), listBox);
              });
  
  
              //Add sorted array value to combobox 
              addArrayItemsToComboBox(entityComboBoxArray.sort(), entityComboBox);
              addArrayItemsToComboBox(yearComboBoxArray.sort(), yearComboBox);
              addArrayItemsToComboBox(typeComboBoxArray.sort(), typeComboBox);
              selectValueForComboBox(entityComboBox, entityValue);
              filterList(fileslistBox, entityComboBox, yearComboBox, typeComboBox);
          }
      }); 
      }
  }
  </code></pre>
  
  <p>But i can't retrieve the documents in the library.
  The documents don't load in my combo box.</p>
  
  <p>It's not possible of use this "listName: listTitle" ? </p>
  
  <p>Best regards,</p>