title: retrieve parameter from executeQueryAsync, javascript
body: <p>I'm trying to retrieve a parameter from a success method that is called within and executeQueryAsync using Javascript ECMA scripting. </p>
  
  <p>I get tried follwing the suggestion here</p>
  
  <p><a href="http://www.learningsharepoint.com/2013/08/07/passing-parameters-to-success-method-in-executequeryasync-sharepoint/" rel="nofollow">http://www.learningsharepoint.com/2013/08/07/passing-parameters-to-success-method-in-executequeryasync-sharepoint/</a></p>
  
  <p>but I get the following error in the MicrosfotAjax.js file:</p>
  
  <p>"The Collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested." in the alert(_returnParam); command, I get an undefined value when instead it should say "hello". I want to demonstrate a simple variable return before I get the success function to return listItemInfo array.</p>
  
  <p>Thank you for your consideration</p>
  
  <pre><code>function Tblsrch(camlstr){
  var siteUrl = '/sites/SIandT%20Project%20Intelligence';
  var hello;
  var clientContext = new SP.ClientContext(siteUrl);
  var oWebsite = clientContext.get_web();
  var oList = oWebsite.get_lists().getByTitle('ISATestdata');
  var camlQuery = new SP.CamlQuery();
  
  camlQuery.set_viewXml(camlstr);
  
      this.collListItem = oList.getItems(camlQuery);
      var _returnParam;
  
  clientContext.executeQueryAsync(Function.createDelegate(this, function(){_returnParam = onQuerySucceeded();}), Function.createDelegate(this, this.onQueryFailed)); 
  
  alert(_returnParam);
  
  }
  
      function onQuerySucceeded(sender, args){
         var listItemInfo = new Array();
         var rowInd = 0;
          var hello;
                      var listItemEnumerator = collListItem.getEnumerator();
  
              while (listItemEnumerator.moveNext()) {
              var oListItem = listItemEnumerator.get_current();
             // listItemInfo += '\nType:' + oListItem.get_item('Name2') + ' | ' + oListItem.get_item('Plan') + ' | ' + oListItem.get_item('Type1');
  
              listItemInfo[rowInd] = new Array(10);
              listItemInfo[rowInd][0] =oListItem.get_item('Name2');
              listItemInfo[rowInd][1] =oListItem.get_item('Type1');
              listItemInfo[rowInd][2] = oListItem.get_item('Plan');
              listItemInfo[rowInd][3] = oListItem.get_item('Analyse');
              listItemInfo[rowInd][4] = oListItem.get_item('Design');
              listItemInfo[rowInd][5] = oListItem.get_item('Build');
              listItemInfo[rowInd][6] = oListItem.get_item('Test');
              listItemInfo[rowInd][7] = oListItem.get_item('Run');
              listItemInfo[rowInd][8] = oListItem.get_item('SupportMaintenance');
              listItemInfo[rowInd][9] = oListItem.get_item('Link1');
              listItemInfo[rowInd][10] = oListItem.get_item('Link2');
  
              rowInd++;
          }
          alert(listItemInfo[0][0] + " " + listItemInfo[0][1] + " " +listItemInfo[0][2] + " " + listItemInfo[0][3] + " " +listItemInfo[0][4] + " " );
      var _returnParam = "hello";
  return _returnParam;
      }
  
  function onQueryFailed(sender, args){
      alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  }
  </code></pre>