cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get entity basetype?

SOLVED
Highlighted
Granite

How to get entity basetype?

Is it possible to determine what a entity is?

I will explain myself:

I would like to make a service which has both as input and output a string.

I insert the name of a entity and it returns

"This entity is a Thing"

"This entity is a Data shape"

"This entity is a username"

Is this possible?

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How to get entity basetype?

Hi Fabio,

Here is the solution for your question.

Community Solution.PNG

Hope it helps!

Andy

View solution in original post

9 REPLIES 9
Highlighted

Re: How to get entity basetype?

Hi Fabio,

Here is the solution for your question.

Community Solution.PNG

Hope it helps!

Andy

View solution in original post

Highlighted

Re: How to get entity basetype?

Thank you!

Highlighted

Re: How to get entity basetype?

That's my method

function getEntityDescription(myEntityName) {

    var collectionName = 'Things';

    var entityType ='Thing';

    var isThing = true;

    var isThingTemplate = false;

    var isThingShape = false;

    var isDataShape = false;

    var isModelTag = false;

    var isNetwork = false;

    var isDataTag = false;

    var isOrganization = false;

    var entity = Things[myEntityName];

    if (entity==null) {

        isThing = false;

        entity = ThingTemplates[myEntityName];

        isThingTemplate=true;

        collectionName = 'ThingTemplates';

        entityType = 'ThingTemplate';

     }

    if (entity==null) {

        isThingTemplate=false;

        entity = ThingShapes[myEntityName];

        isThingShape = true;

        collectionName = 'ThingShapes';

        entityType = 'ThingShape';

     }

    if (entity==null) {

        isThingShape=false;

        entity = DataShapes[myEntityName];

        isDataShape = true;

        collectionName = 'DataShapes';

        entityType = 'DataShape';

     }

    if (entity==null) {

        isDataShape=false;

        entity = ModelTags[myEntityName];

        isModelTag = true;

        collectionName = 'ModelTags';

        entityType = 'ModelTagVocabulary';

     }

    if (entity==null) {

        isModelTag=false;

        entity = Networks[myEntityName];

        isNetwork = true;

        collectionName = 'Networks';

        entityType = 'Network';

     }

    if (entity==null) {

        isNetwork=false;

        entity = DataTags[myEntityName];

        isDataTag = true;

        collectionName = 'DataTags';

        entityType = 'DataTagVocabulary';

     }

    if (entity==null) {

        isDataTags=false;

        entity = Organizations[myEntityName];

        isOrganization = true;

        collectionName = 'Organizations';

        entityType = 'Organitzation';

    }

     return {

    name: myEntityName,

        entity: entity,

        isThingShape: isThingShape,

        isThing: isThing,

        isThingTemplate: isThingTemplate,

        isDataShape: isDataShape,

    isModelTag: isModelTag,

    isNetwork: isNetwork,

    isDataTag: isDataTag,

    isOrganization: isOrganization,

        collectionName: collectionName,

        type: entityType

     };

}

Highlighted

Re: How to get entity basetype?

Would be good to know which method it's faster...

Highlighted

Re: How to get entity basetype?

Ok I did some tests,

Iterating 1000 times over both functions, my method last at max 10ms ( for 1000 iterations ), the SearchModelEntities method lasts for 15000ms ...

Highlighted

Re: How to get entity basetype?

Oh, that's a great point.

Even because your method was quite similar to mine.

I have this input which can be Username, Thing, ThingTemplate.

My metod was

var isUser = (Users[myInput]) ? true : false;

var isThing = (Things[myInput]) ? true : false;

var isTemplate = (ThingTemplates[myInput]) ? true : false;

so, tecnically, it's even faster since it has to choose between three.

I just asked because I believed it was not too orthodox

Highlighted

Re: How to get entity basetype?

Your are good to go with you method.


With Search method you must use Search resources, with ModelEntityCollection[] method you are working with In-Memory objects, that's why it's a way faster.

Highlighted

Re: How to get entity basetype?

One second, your solution Fabio has a problem, look at my General Performance Recommendations and some perks (unofficial) document.

You should check always explicit --> (Users[myInput])? true : false; should be (Users[myInput]!==null)

and so on.

Highlighted

Re: How to get entity basetype?

Oh, ok. Thanks!

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!