0

I am trying to pass data to a callback function but it doesn't work...

I am using Salesforce "searchAndGetScreenPopUrl" method which is calling callback function. I want to be able to pass some data to that callback function.

Here is the code:

var test = "some data";
sforce.interaction.searchAndGetScreenPopUrl('07411111111', '', '', callback);

And here is my callback function:

var callback = function (response) {
    if (response.result) {
        recordFound = JSON.parse(response.result);
        appendPhone = phonecallBox(recordFound); // get phone call box
        $('#box').append(appendPhone).hide().fadeIn('slow');
    } else {
        alert(response.error);
    }
};

Unfortunately passing the data like this doesn't work:

var test = "some data";
sforce.interaction.searchAndGetScreenPopUrl('07411111111', '', '', callback(test));

It comes back with "undefined".

1 Answer 1

2

In JavaScript values from a parent scope are visible in the child scope. So in this case you can just directly reference the value of test in the callback function:

var test = "some data";
var callback = function (response) {
     ...
     console.log('test=' + test);
     ...
};

The callback function is invoked by code outside your control which is why you can't pass a reference to test as a function parameter.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .