Event Handler req.item object is incomplete

I have an event handler that have stopped working as of today. I did not change anything. I noticed that the problem is that it cannot read the property ‘channel’ from the req.item that is passed in the event handler.

In the code below, the event error out on the line
var channel = req.item.category.channel

Nothing changed since yesterday and this was working fine. You can test it be sending a REST CONSOLE B7F833A2-7B82-DECF-FF25-3555BC74F600 with this body:

My application ID is B7F833A2-7B82-DECF-FF25-3555BC74F600

{
“title”: “this is a test”,
“details”: “This is only a test”,
“category”: {
“___class”: “Category”,
“channel”: “Testing”
}
}

Backendless.ServerCode.Persistence.beforeCreate('Notification', function(req) {
  //add your code here
  var CategoryStore = Backendless.Data.of('Category');
  var channel = req.item.category.channel;
  var queryBuilder = Backendless.DataQueryBuilder.create()
    .setWhereClause("channel = '" + channel + "'")
    .setRelated( [ "parentCategory", "parentCategory.parentCategory" ] );

    return new Promise((resolve, reject) => {

      CategoryStore.find(queryBuilder)
        .then(categories => {
          
          if (categories.length == 0) {
            queryBuilder.setWhereClause("objectId = '09881500-C33F-04CA-FF04-AFA8CDA02700'")
          CategoryStore.find(queryBuilder)
            .then(categories => {
              req.context.crossHandlerData = { category: categories[0] };
              resolve();
            })
            .catch(err => {
              reject('Could not get default Category. Error: ' + err.message);
            });
        }
        else {
          req.context.crossHandlerData = { category: categories[0] };
          resolve();
        }
          
        })
        .catch(err => {
        reject('Error retrieving category. Error: ' + err.message);
      });
      
    });
});

Hi Gabriel,

Have you tried logging out req.item to see what it actually contains?

Yes, it has everything except the category sub object.

Notice that category is undefined! This was working yesterday and I did not change anything.

2017-11-30 18:29:55,710 | SERVER_CODE | INFO | Notification {
___class: ‘Notification’,
ownerId: undefined,
objectId: undefined,
created: undefined,
updated: undefined,
category: undefined,
title: ‘this is a test’,
details: ‘This is only a test’,
___jsonclass: ‘Notification’ }

We found the problem, will be fixed in an hour approximately. Sorry for the inconvenience.

OK will check back in 1 hour to confirm.

Works now, please verify.

It works. Thanks.