function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NinoJoseNinoJose 

Is it possible to pass a variable on the callback function?

    Hi guys, I would like to know if It is possible to pass a variable on the callback functions besides the result of the query or action?

Any comment/suggestion will be deeply appreciated.
NinoJoseNinoJose
I think there is no way to pass a variable on the callback function.

 However, I stumbled upon this thread
http://community.salesforce.com/sforce/board/message?board.id=ajax_toolkit&message.id=4206 with cheenath's reply regarding closure in javascript and now don't need to pass the variable on the callback function.
cheenathcheenath
Yes, you can pass any object to callback method, by using "source".
Example below:

  var result = sforce.connection.query("Select Name,Id from User", {
      onSuccess : success,
      onFailure : failure,
      source : "This can be any js object"
    });

  function success(result, source) {
    alert(source);
    var records = result.getArray("records");

    for (var i=0; i<records.length; i++) {
      var record = records[i];
      log(record.Name + " -- " + record.Id);
    }
  }

  function failure(error) {
    log("oops something went wrong " + error);
  }





NinoJoseNinoJose
Hi cheenath,

Its been a while since i have been online. I try this code you've given me. Thanks


Message Edited by NinoJose on 04-27-2008 06:53 AM