1

I spilled 8 hours on this piece of code that just does not want to work

On localhost and javascript it works great, but in the parse.com cloud code i get undefined for a variable.

Parse.Cloud.define("goGetPrices", function(request, response) {

var price;

function getPrices(stockPrice){
console.log(stockPrice);

var PriceTick = Parse.Object.extend("StockPrices");
var queryInstal = new Parse.Query(Parse.Installation);

var queryLess = new Parse.Query(PriceTick);
var queryMore = new Parse.Query(PriceTick);

queryLess.equalTo("Position","Less");
queryLess.greaterThan("Price", stockPrice);

console.log(PriceTick) // RETURNS UNDEFINED
console.log(queryInstal) // RETURNS UNDEFINED

Because those return undefined the rest of the code can't work...the weird thing is this works great on my localhost without cloud code

queryLess.find({
success: function(results) {
//Less than

console.log("found less");

 if (results.length) {

for (var i = 0; i < results.length; i++) { 
var object = results[i]

var devicetoken = object.get('devicetoken');
var objID = object.get('objectId');

console.log("Got Less");
queryInstal.equalTo('deviceToken', devicetoken);
queryInstal.equalTo('deviceType', 'ios');

Parse.Push.send({
  where: queryInstal, // Set our Installation query
  data: {
    alert: "The price is now: "+stockPrice
  }
}, {
  success: function() {
    // Push was successful
          object.destroy({});


  },
  error: function(error) {
    // Handle error
  }
});
}
}},
 error: function(error) {
  alert("Error: " + error.code + " " + error.message);
 }
});




Parse.Cloud.httpRequest({
url: "example.php",
dataType: 'json',
type: 'GET',
success: function(data) {
 price = data.data.Response.price;
 response.success("yes")
 getPrices(price);

},
error: function(data) {
  response.error('Request failed with response code ' + data.status);

}
}); });
3
  • Does the code have to change because it's on cloud ?? Commented Jan 5, 2014 at 11:23
  • In getPrices(), does console.log(stockPrice) return what you expect? Commented Jan 5, 2014 at 17:35
  • No it doesn't return anything. It should send a push but nothing happens... I can confirm that it gets into the loop. Commented Jan 5, 2014 at 18:29

1 Answer 1

2

You have to use Parse.Query(ClassName), where ClassName is a name string or instance of Parse.Object subclass:

https://parse.com/docs/js/symbols/Parse.Query.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.