Start a new topic

Help with collection hooks / business logic

I'm trying to figure out business logic.



I have a collection hook in place using the code from this example http://stackoverflow.com/questions/20057292/kinvey-business-logic-example-of-saving-new-object-on-collections-javascript



The only thing changed is the collection name however I'm getting this error:

"error": "BLRuntimeError",

"description": "The Business Logic script has a runtime error. See debug message for details.",

"debug": "UnallowedError: Method 'response.continue' is not allowed in this context."





no matter what I try I can't seem to access global variables within the callback - any suggestions.

response.continue() works in collection hooks, but not in custom endpoints. In custom endpoints (and in collection hooks if you want to end execution of a request), use response.complete(). For more information on completing business logic, see http://devcenter.kinvey.com/guides/business-logic#completion
Thanks for your help Michael.



How do I access the response object from within the modules callback? All I'm trying to do is average data from one collection and update another collection item with that average.
I'm not sure what you are asking - the response object should be accessible in any callback, as long as the function occurs within the scope of the onRequest function.
https://www.dropbox.com/s/8eroclqsj85jgqe/Capture.PNG



The request only completes when the following is outside of the callback.



response.body = docs;

response.complete(200);



You can see in the image, the response object is blue only when outside the callback. The docs object is only blue if it's inside the callback. Even if I declare the docs (or some other) variable before the module class, I cannot set/update it from within the callback.



I hope this makes sense - it's hard for me to explain - I'm a noob!
Login or Signup to post a comment