0

I am trying to run the following parse background job in Cloud Code

   Parse.Cloud.job("sendAlert", function(sendAlert) {
     Parse.Push.send({
       data: {
       "content-available": 1,
       }
     }, {
     success: function() {
   status.success("Push Worked!!!");
   },
   error: function(error) {
    status.error("Uh oh, something went wrong.");
   }
  });
 });

with the intended result of, when it is run, a "transparent" (not seen by users, but seen by the app) push being sent to users.

When I run it, I get the error

Jobs: sendAlert E2015-02-20T19:17:22.637Z] v17: Ran job sendAlert with: Input: {} Failed with: ReferenceError: status is not defined at Object.Parse.Push.send.error (main.js:12:5) at Parse.js:2:7940 at f (Parse.js:2:6852) at Parse.js:2:6344 at Array.forEach (native) at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661) at c.extend.reject (Parse.js:2:6297) at Parse.js:2:6956 at f (Parse.js:2:6852) at Parse.js:2:7386

in the log. What am I doing wrong? Thanks, and appreciate it - total Parse novice here.

1
  • Could you please properly indent your code? Commented Feb 20, 2015 at 19:41

1 Answer 1

1

If you look for the word status in your code, you will see that you haven't declared it anywhere. A variable named status can't just come out of nowhere, so that's why you're getting a ReferenceError.

According to the documentation, the second parameter passed into the Parse.Cloud.job() callback is a JobStatus object with error and success methods, so it seems that's what you're trying to use:

//                       declare it here   ---------v
Parse.Cloud.job("sendAlert", function(sendAlert, status) {
    Parse.Push.send({
        data: {
            "content-available": 1,
        }
    }, {
        success: function() {
            status.success("Push Worked!!!");
        },
        error: function(error) {
            status.error("Uh oh, something went wrong.");
        }
    });
});
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, how do I declare it? I am new to Parse. Thanks, and sorry.
hmm, perhaps I am misunderstanding the error... now it is failing with the error function: Ran job sendAlert with: Input: {} Failed with: Uh oh, something went wrong..
@rocket101 Yes, that means that your Parse.Push.send() is failing and that your error callback is being called. I wouldn't know why it is failing, but that's a completely separate matter from the issue in your question. I would suggest making use of the error parameter that you have there to get some idea of what went wrong: status.error("Uh oh, something went wrong." + error);
you need to specify some more parameters for the push, such as a query or a channel. Again, check out the documentation

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.