Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Backendless.ServerCode.enablePromises()
  2. Backendless.ServerCode.Persistence.beforeCreate('venues_table', function(req) {
  3.  
  4.     //after calling enablePromises, all asynchronous operations now return a Promise which
  5.     //is very convenient in our case, because we may return it to the CodeRunner
  6.     return Backendless.Counters.of( "venue_counter" ).incrementAndGet().then(
  7.         counter => {
  8.             console.log( "[ASYNC] counter value is - " + counter );
  9.  
  10.             req.item.venue_id = counter
  11.         },
  12.         error => {
  13.             console.log( "error - " + error.message );
  14.  
  15.             //throwing the error will interrupt venues-table record creation
  16.             //throw e
  17.         }
  18.     );
  19.  
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement