Mr. Meeseeks Mr. Meeseeks - 3 months ago 12
Javascript Question

ParsePromise get the result

I want to get the promise result of this object from chrome browser console log I tried to call it by using the code below and there are no response in console.



var promise = Parse.Cloud.run('retrieveProviderStatus', { providerId: data.id })
.then(function(result) {
return result;
}, function(error) {
return error.message;
});
console.log(promise._result[0]);




Answer

Since it's a promise your console statement would need to be in the success function. In your example the promise has not resolved itself by the time you are executing console.log

Parse.Cloud.run('retrieveProviderStatus', { providerId: data.id })
            .then(function(result) {
                console.log(result)
            }, function(error) {
                // do whatever on error
            });

Alternatively resolve the promise separately if you need to massage the data that gets returned.

var promise = Parse.Cloud.run('retrieveProviderStatus', { providerId: data.id })
            .then(function(result) {
                return result;
            }, function(error) {
                return error.message;
            });

promise.then(function(result) { 
  console.log(result)
})
Comments