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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

How to programatically check if ThingShape or ThingTemplate exists ?

JD_10518393
7-Bedrock

How to programatically check if ThingShape or ThingTemplate exists ?

I have a scenario where I am executing a  child service (inputs: ThingShape, Thing and Boolean) from another wrapper service. Now the child service fails if I pass a ThingShape that does not exist, so I am trying to write something like:
If ThingShape Exists :
TS = TS_NAME
Else:
TS = undefined.

How do I achieve this ?

I have checked many OOTB services but none help with this.

TWX v9.3.4

ACCEPTED SOLUTION

Accepted Solutions

if (!!!ThingShapes[TS]) {
TS = "gggg";
logger.info("ThingShape " + TS + " does not exist.");
} else {

logger.warn("ThingShape " + TS + "exists.");
}

View solution in original post

2 REPLIES 2

if (!!!ThingShapes[TS]) {
TS = "gggg";
logger.info("ThingShape " + TS + " does not exist.");
} else {

logger.warn("ThingShape " + TS + "exists.");
}

It's correct, but you could simply write

if (ThingShapes[TS])
    logger.warn("ThingShape " + TS + "exists.");
else 
    logger.warn("ThingShape " + TS + " does not exist.");

which is a bit cleaner and easier to read/less surprising (KISS principle).

Announcements


Top Tags