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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

How to programatically check if ThingShape or ThingTemplate exists ?

JD_10518393
1-Newbie

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

1 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.");
}

Rocko
17-Peridot
(To:JD_10518393)

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).

Top Tags