Load Table Objects not an Object? How to test for returned data?

I used a Load Table Objects block to load a variable. The query returns data, so I know that works. If I check if the variable is an object it returns false. If I check if it is an array, it returns true.

I thought Load Table Objects return an object, but it looks like it’s an array of objects, but not an object itself.

Realtime output -
https://magicaljelly.backendless.app/api/services/sellers/getrelatedsellers?MicrostoreId=3

What is the best way to check if a Load Table Object has results?

Load Table Objects always returns a list. Even if the result of the query is one object, it will be in a list.

Thanks, @mark-piller. Is a list an array? What is the best way to check if Load Table Object has results?

List and array in the Codeless world are used interchangeably. The best way to check if a list is empty is to use the following block:
Screenshot_2022-06-03-20-12-05-85_40deb401b9ffe8e1df2f1cc5ba480b12

Thanks @mark-piller.

I tried to use the “is empty” block with a “not” block before it and it’s not working. Is that not allowed for some reason?

Tim

It is allowed. Is it reporting an incorrect result or an error? Did you use print to see what the length of the collection is?

This works -

This does not work. The only change is the type of check on dbObject.

Could you please narrow down “this works” and “this doesn’t” to something specific in that logic? I can see about a dozen of places where things could go wrong

Fair enough. The first example returns the results I expect. The second returns an empty object.

I’m open to a better way to structure this so there aren’t all the places this could go wrong.

Hopefully, this makes sense:

That does make sense overall.

Objects are never empty

This is a backendless thing, right? Other languages have “is empty” for objects.

Tim

No, it is not a Backendless thing. In my mind, you either have an object or you have null.

What would an empty object mean? That it has no properties?

Either way, the is empty block works only with lists/collections.

jQuery.isEmptyObject() | jQuery API Documentation is what I was thinking of.

If you had something like

var = array();

The var is an array object, but the object itself is empty right?

I guess var.length would do the same but checking the length of an object seems weird to me. Is the length string length, the number of elements?

Thanks for the help!

Tim

jQuery is not a language…:wink: the isEmptyObject is not a standard thing, but a utility method defined by jQuery.

Arrays in JS are special types of objects. The best way to check if an array is empty is to check its length which returns the number of elements in it:
Load Table Objects not an Object? How to test for returned data? - UI Builder - Backendless Support 2022-06-06 13-07-50

HA! The platform that calls the endpoint uses jquery so I’m trying to work in a similar fashion.

Tim