Parse.Cloud.beforeSave not working.

579 views
Skip to first unread message

Alexis L.

unread,
Mar 2, 2017, 4:49:21 AM3/2/17
to back{4}app
Hello,

I have a problem with  Parse.Cloud.beforeSave, where I update a field based on the values of other fields in the same object. I can see that  beforeSave is executed, and the value that I'm setting is taken into account, "credit_usd":101.

{"title":"20 Credits ","tid":"1000000278240855","pid":"com.XXXX","price":1.99,"currency":"EUR","currencySymbol":"€","state":1,"user":{"__type":"Pointer","className":"_User","objectId":"XXXX"},"isValidReceipt":false,"createdAt":"2017-03-02T08:11:33.578Z","updatedAt":"2017-03-02T09:13:27.250Z","credit_usd":101,"ACL":{"XXXX":{"read":true}},"test":102,"objectId":"XXXXX"}

However, this doesn't reflect in the dashboard, or through queries to the said object. The beforeSave trigger is pretty standard, but for debugging purposes, I've made it minimalistic :

Parse.Cloud.beforeSave('mysaidclass', function(request, response) {

  if (request.object.get('user') === undefined ){

    response.error('no user defined');

    return;

  }

  request.object.set('credit_usd',101);

  response.success('ok')

  return;

});


Even this doesn't work, and doesn't generate error messages on cloud code either. It seems the fct call is executed, but the database entry not changed. The are no other triggers depending on this one, or subsequently triggered after this one. All beforeSave on this class are isolated, and do not incur triggers on other classes (verified through server logs)

I have other classes, with beforeSave triggers that are working just fine.

Any idea what's going on?



Alexis L.

unread,
Mar 3, 2017, 1:19:12 PM3/3/17
to back{4}app, casag...@back4app.com
Hello
Here's the full beforeSave..

Parse.Cloud.beforeSave('myClass', function(request, response) {

 
if (request.object.get('user') === undefined ){
    response
.error('no user defined');
   
return;
 
}

 
if (request.object.get('country_code') === undefined ){
    response
.error('no country_code defined');
   
return;
 
}
 
var query = new Parse.Query('myOtherClass');
  query
.equalTo('country_code',request.object.get('country_code'));
  query
.find({useMasterKey:true}).then(function(results){
   
if (results.length == 0) {
      response
.error(" no country code found for " + request.object.get('country_code'))
   
}else{
      request
.object.set('prefix', result[0].get('prefix'));
      response
.success();
   
}
 
},function(error){
    response
.error(error.message + "\n" + error.stack);
 
});
});

When the trigger is present, I can't save a class instance - it just times out - and I see nothing in the logs.
When I remove the trigger, I can save a class instance just fine.

This trigger is pretty standard, am I missing anything here? Is there some debugging feature I can enable to at least figure out what H...k is going on?

-A



Alexis L.

unread,
Mar 4, 2017, 1:34:49 AM3/4/17
to back{4}app, casag...@back4app.com
it was 

      request.object.set('prefix', result[0].get('prefix'));


instead of 'result'... should read 'results'.... No idea why it turned out into something un-debuggable (even if 'result' was thereafter defined as a global variable).

Anyway, all set 

casag...@back4app.com

unread,
Mar 15, 2017, 10:09:53 AM3/15/17
to back{4}app, casag...@back4app.com
Hello Alexis,

Were you able to solve your issue, then?

Best!

Alexis L.

unread,
Mar 15, 2017, 12:55:07 PM3/15/17
to back{4}app, casag...@back4app.com
Yes, I'm all set. It was my bad...
Reply all
Reply to author
Forward
0 new messages