How to tell if an Object is an Entity, Entity Sel, or simple Obj?

17r6+

Let’s say that I’m in a generic method that receives an object.

How can I tell if the object is a “simple” object, vs an Entity, or an Entity Selection, or a Formula (or other type of object???)?

I’m sorry if this has been addressed before.

Currently not available! But i have a workaround. Come to my session in Paris or Chicago to receive all tips. :mrgreen:

The workaround is, that you have to test for attributes or functions (ON ERR CALL).

Christian,

Thanks for the reply.

test for attributes or functions
I thought about doing the same thing: but wondered if there is a better way.

If there’s not: then I’ll create a feature request.

Hi Tony,

It’s not a great solution due to the overhead of stringify, but you could use JSON Stringify and test the result.

<code 4D>
$json:=JSON Stringify($obj)
Case of
: ($json=""[object Formula]"")
ALERT(“Formula”)
: ($json=""[object DataStore]"")
ALERT(“Data Store”)
: ($json=""[object DataClass]"")
ALERT(“Data Class”)
: ($json=""[object EntityCollection]"")
ALERT(“Entity Collection”)
Else
ALERT(“simple object”)
End case

</code 4D>

Possibly it wouldn’t work for different languages though.

I agree though, something like If (Object type($obj)=Is Data Store) would be a good feature.

Hi,

Yes, at the moment you can test the length attribute to verify the object is an entity selection.

If there is no length attribute and the getDataClass() member method returns something it is an entity.