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);
});
});
});