Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hello,
I have a requirement, to check if a particular entity (input - name, type) exists in Thingworx or not. For that, I came across 'EvaluateVisibilityPermissions'
var params = { name: EntityName /* STRING */, type: "MediaEntity" /* STRING */ }; // result: BOOLEAN var isExist = Resources["SecurityServices"].EvaluateVisibilityPermission(params);
But this method comes with a limitation that, if the permission is not set to the user, this service returns false.
What I would like to have is check if the entity is present or not, regardless of visibility permissions.
For that I came across a resource https://support.ptc.com/cs/help/thingworx_hc/thingworx_7.0_hc/index.jspx?id=ID103384447&action=show 'Entity Utilities'.
This class (EntityUtilities) has a method, "findEntityDirect" which can solve my purpose, but I am not able to understand how to use this method in my custom Thingworx services. If I understand correctly it is similar to "EntityServices" (http://support.ptc.com/cs/help/thingworx_hc/thingworx_6.0_hc/index.jspx?id=ID1410648636&action=show). I am able to see 'EntityServices' while creating my custom service in snippets, but I cannot find 'EntityUtilities'. Refer attached image.
Please let me know how to get EntityUtilities class, so that I am able to use 'findEntityDirect' method.
Thanks in advance
Aditya Mittal
Solved! Go to Solution.
This is my code to get a reference to any kind of entity:
function getEntity(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 }; }
with it, you can easily can do the following check:
var entityExists = (getEntity(theEntityName).entity!=null);
This is my code to get a reference to any kind of entity:
function getEntity(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 }; }
with it, you can easily can do the following check:
var entityExists = (getEntity(theEntityName).entity!=null);