Backendless Support
 
Solved

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"

}

}

  1. 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);

    });

    });

    });

Leave a Comment

Comments (7)

photo
1

Hi Gabriel,

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

photo
1

Yes, it has everything except the category sub object.

photo
1

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' }

photo
1

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

photo
1

OK will check back in 1 hour to confirm.

photo
1

Works now, please verify.

photo
1

It works. Thanks.

photo