To utilize Cloud Code for Data you must subscribe to one or more events. On those events you can execute custom business logic, validate the incoming requests, or modify the response. The events are located in Everlive.Events. Telerik Platform supports the following events:

  • Before Read (beforeRead)
  • After Read (afterRead)
  • Before Create (beforeCreate)
  • After Create (afterCreate)
  • Before Update (beforeUpdate)
  • After Update (afterUpdate)
  • Before Delete (beforeDelete)
  • After Delete (afterDelete)
  • Before Aggregate (beforeAggregate)
  • After Aggregate (afterAggregate)

These events are triggered for data contained in the following:

  • The Users system content type.
  • All custom content types.
  • Content types linked to (Data Connectors, but only when accessed through the Backend Services APIs.

The before, or pre-processing, event handlers execute just before Telerik Platform processes the actual request. Pre-processing event handlers take three arguments: request, which contains information about the request that is waiting to be processed, context, which you can use to pass parameters to the after (post-processing) event handlers, and done.

The after, or post-processing, event handlers, take request, which contains information about the request that was just processed, response, which contains the information processed by Telerik Platform, context, which again connects the post-processing functions with pre-processing, and done.

All event handler functions have done as their last parameter. Always call this function (done()) from within your code when you are done executing your custom logic. Not doing so will stall the execution until the general Cloud Code timeout expires and will result in an error regardless of what your code returns.

Tip

Avoid keeping empty event handlers, where the only thing that you do is call done(). Either comment them out or delete them from your code to optimize performance.

The full structure of the request, response, and context objects is described in Cloud Code Parameters Reference.

Cloud Code execution is restricted in a number of parameters for security and performance reasons. See Restrictions of Cloud Code for Data.

For your convenience, the Business Logic Explorer for each content type includes template code with handlers for each supported event. All you have to do is enter your code between the opening bracket for each handler and the done() call.

The following example shows the template for the beforeRead event handler:

Everlive.Events.beforeRead(function(request, context, done) {
    //Enter your custom code here

    //Call done() once you are finished
    done();
});

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.