0

I've got an afterSave handler in Cloud Code that conditionally calls a custom method.

From my testing, both functions appear to be working exactly as desired. The custom method is skipped appropriately (with confirming console messages looking correct). It is also called appropriately, and the custom method creates a new object exactly as desired.

What's confusing me is that when the custom method IS called, I get something like the following in my Cloud Code log:

Input: {"title":"title","ownerId":"ownerId"}
Result: undefined

Like I said, the values seem to be passed in correctly, and the method seems to run correctly, but I don't understand why I get Result: undefined.

In the method that is called, I've placed a response.success() or response.error() in every pathway that's possible.

So, is this something to worry about?

The custom method is a "fire-and-forget" type of method, so my afterSave method doesn't wait around for a response. Is that why I'm getting Result: undefined?

mbm29414
  • 11,558
  • 6
  • 56
  • 87

1 Answers1

4

The reason you are getting undefined is because your response and error functions don't pass any values. Replace it with this.

success: function(result) {
    //...
    response.success(result);
},
error: function(error) {
    response.error(error);
}

Then you'll no longer have an undefined result.

Dehli
  • 5,950
  • 5
  • 29
  • 44
  • 1
    Alternatively, if you really don't want to return anything, but still don't want the response to be "undefined", you can do response.success({}); – Tom Erik Støwer Sep 20 '14 at 14:39
  • Ah, ok. I was doing `response.error(error)`, but just `response.success()`. That's great to know! So, just a `response.success('success')` seems like a good solution, then, right? – mbm29414 Sep 20 '14 at 14:41
  • Yup, that would work! You can respond with anything you'd like. – Dehli Sep 20 '14 at 14:50