Cannot read property 'xxx' of undefined

I’m getting a cannot read property on the business logic attached… Would I be right in assuming I should be seeing the column imageFilename from the table that the event handler is based on?

Thanks
Pat

If the object in the request has that property, then you should be able to see it. Use the print block to log any debug information you need. The log output can be found in the log file located in the Files sections, then /logging directory and then the file with today’s date. Log information can be seen in Real-time logging window available from Manage > Logging > Real-time.

Ok - I’m getting the attached message - bound to be something I’m doing (or not!)

Add some of your logging so you can see what the code is getting in the request.

This block
Screenshot 2020-05-11 at 20.02.49

gives me

How about logging the entire request object just to see what’s in it?

Doesn’t appear to be a great deal in there… I printed out the request, context etc

You see the request in the log now. Does it contain the property the code is trying to obtain?

Afraid not…

Mon May 11 2020 20:35:04 GMT+0100 (British Summer Time) | SERVER_CODE | INFO | [10373] --------- REQUEST --------

Mon May 11 2020 20:35:04 GMT+0100 (British Summer Time) | SERVER_CODE | INFO | [10373] { context: { ___jsonclass: ‘com.backendless.servercode.RunnerContext’, deviceType: ‘IOS’, crossHandlerData: {}, userLocale: ‘en’, httpHeaders: null, userId: ‘1C758501-1B77-E32C-FF2C-4E1F7CB09D00’, eventContext: ‘inventoryImages’, userRoles: [ ‘AuthenticatedUser’, ‘IOSUser’ ], userToken: ‘DC4B1810-48D1-27C1-FF33-A09700AEB900’, prematureResult: null, missingProperties: {}, appId: ‘AEDE5BD0-8EAF-92AB-FF8F-4B7F9646D500’, httpResponseHeaders: {}, userRole: [ ‘AuthenticatedUser’, ‘IOSUser’ ] }, itemId: ‘B685BE18-DF33-4321-FF85-66ED2B53FA00’ }

I am not sure what your expectation is here… You’re adding an event handler for the remove API. Here’s the REST doc for that API:
https://backendless.com/docs/rest/data_single_object_deletion.html
As you can see the only thing the API has is the objectId value of the object to be deleted. That’s it! And your event handler does get that value from the request:

itemId: ‘B685BE18-DF33-4321-FF85-66ED2B53FA00’

So when you try getting imageFilename from the request, it doesn’t really make any sense, since there is no such thing in the request.

Regards,
Mark

ah - ok - understood…

When I delete an image from a table I also want to remove the file itself from the directory, I was hoping to do that using business logic in a before removal block rather than the app making a second call to backendless.

I assumed, wrongly, that I would have access to the table information (including the filename) as I would using a before delete trigger. I figured that information would be available in a Before Remove handler.

When I looked at the drop down list in Get Request Object Property I see every column in the table I’m working with so thought it’d work… So what are those values for if they aren’t available?

They (column names in the dropdown) would make more sense in the create/update object events.

In your case, you need to do the following in your event handler:

  1. retrieve the object using provided objectId
  2. get the path of the file from (1)
  3. delete the file based on (2)

I think I’m just going to make a second call via the file API.

TBH I just feel I’m fumbling in the dark trying to get stuff done in the codeless editor trying to do pretty straightforward stuff. The stuff I’ve done works and works well - but trying to extract data from a table, work out how to store it, how to iterate through it and extract a property, store that - build a path and then delete it… I (we) are spending too much time on this.

Something like this. Maybe I got used to it. I find it quite intuitive.

Seems to give me what I need - thanks

I got a lot of this down but the list thing was where I was falling down. Is there a video guide on how to do the backendless codeless thing? I’m not finding the docs very helpful + videos are more my thing learning wise.

(Thanks for your patience on this - it is appreciated)

Hi Patrick,

here is a playlist of 12 useful vidz related to Codeless:


Hope this will help you!

Regards,
Stanislaw

thanks - I’ll get into these…