title: javascript variables not getting passed to function
body: <p>For some reason on line 54(which is starred out************) an error is popping up saying cannot call 'push' of undefined.  My 'randUsers' array which is supposed to initially be empty is not getting passed properly. Why isn't randUsers getting passed properly?</p>
  
  <p>This cloud code on Parse.com is getting triggered by an afterSave function.  I declared the variables so they would be global variables, but idk if the fact that this is cloud code and not a regular implementation file affects that. </p>
  
  <pre><code>  var leanBody = "";
    var leanSenderName = "";
    var leanSenderId = "";
    var randUsers = [];
  
  function varReset(leanBody, leanSenderName, leanSenderId, randUsers){
     leanBody = "";
     leanSenderName = "";
     leanSenderId = "";
     randUsers = [];
     console.log("The variables were set");
  }
  
  
  Parse.Cloud.afterSave("Lean", function(request, leanBody, leanSenderName, leanSenderId, randUsers) {
    varReset(leanBody, leanSenderName, leanSenderId, randUsers);
  
    var leanQuery = new Parse.Query("Lean");
    leanQuery.first({
      success: function(results){
        console.log("The first object was retrieved");
        leanBody = (results.get("messageBody"));
        leanSenderName = (results.get("senderName"));
        leanSenderId = (results.get("senderId"));
        getUsers(leanBody, leanSenderId, leanSenderName, randUsers);
        results.destroy({
          success: function(results){
            console.log("deleted");
          }, error: function(results, error){
          }
        });
      }, error: function(error){
      }
  
    });
  });
  
    function getUsers(randUsers, response, leanBody, leanSenderName, leanSenderId, randUsers){
      var query = new Parse.Query(Parse.User);
      query.find({
          success: function(results, leanBody, leanSenderName, leanSenderId, randUsers){
              var users = [];
              console.log("results = " + results);
              //extract out user names from results
              for(var i = 0; i &lt; results.length; ++i){
                  users.push(results[i].id);
              }
              for(var i = 0; i &lt; 3; ++i){
                  var rand = users[Math.floor(Math.random() * users.length)];
                  var index = users.indexOf(rand);
                  users.splice(index, 1);
                  randUsers.push(rand);**********************************************
                  }
              console.log("rand = " + rand);
              console.log("The random users are " + randUsers);
              response.success(sendLean(leanBody, leanSenderId, leanSenderName));
          }, error: function(error){
              response.error("Error");
          }
      });
    }
  
    function sendLean(randUsers, leanBody, leanSenderName, leanSenderId){
      var Mission = Parse.Object.extend("Mission");
      var mission = new Mission();
      for(var i = 0; i &lt; 3; ++i){
        mission.set("messageBody", leanBody);
        mission.set("recipientId", randUsers[i]);
        mission.set("senderName",  leanSenderName);
        mission.set("senderId", leanSenderId);
        mission.save(null, {
          success: function(mission) {
            // Execute any logic that should take place after the object is saved.
            alert('New object created with objectId: ' + mission.id);
          },
          error: function(mission, error) {
            // Execute any logic that should take place if the save fails.
            // error is a Parse.Error with an error code and message.
            alert('Failed to create new object, with error code: ' + error.message);
          }
        });
      }
    }
  </code></pre>