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

Provide a way to check for things visibility [DONE IN 8.5]

0 Kudos

Provide a way to check for things visibility [DONE IN 8.5]

TL;DR This now works as expected in 8.5, see comments below.

 

Hello,

 

Please consider a couple of use cases, both of which we encountered on the same project:

  1. We have a "collection of things" entity, which contains an infotable with thing names. We would like to list them in a mashup, filtering by visibility.
  2. We have a gateway (e.g. an AxedaEMessageGatewayModel), which contains the list of connected assets. Again, we would like to display them to the end user, filtered based on his visiblity.

 

As far as I know (please correct me if I'm wrong), in ThingWorx there's no simple way to verify things visibility efficiently. The logic that currently applies is as follows:

 

var t = Things['TestThing'];
if (t === null) {
    logger.debug('Thing does not exist');
} else {
    try {
        var n = t.name; // This will throw an exception if the thing is not visible
        logger.debug('Thing exists and visible');
    } catch(e) {
        logger.debug('Thing exists and not visible: ' + e);
    }
}

 

 

Even though it allows to detect invisible things, it has a nasty side effect of polluting script logs with irrelevant error messages, which are logged even if you catch all exceptions (besides, the code uses exception handling for controlling program flow, which is a known antipattern).

 

Workarounds include using Spotlight search (slow and deprecated), GetImplementingThings (just slow) and writing custom extensions (complex). I'd like to propose introducing some system service, e.g. IsVisibleToCurrentUser(), which we could trigger to detect whether the thing is visible or not. It may be the only service which is safe to execute on invisible things:

 

 

var t = Things['TestThing'];
if (t === null) {
    logger.debug('Thing does not exist');
} else {
    if (t.IsVisibleToCurrentUser()) {
        logger.debug('Thing exists and visible');
    } else {
        logger.debug('Thing exists and not visible');
    }
}

 

 

 

Other people experienced the same issue before and invented their own workarounds (none of which work in our case, unfortunately), e.g.: https://community.ptc.com/t5/ThingWorx-Developers/check-if-user-has-visibility-on-a-thing/td-p/56969... 

 

/ Constantine

6 Comments
Alessio
15-Moonstone

Hi

are you asking for a service to tell some user A executing the service whether a particular thing “exists and is visible to user A” or “exists and is not visible to user A” or “does not exist”?

 

This would be a security anti-pattern. 

 

Constantine
16-Pearl
Alessio,

Ideally I’d like the Things[name] to be null if I don’t have visibility.
Unfortunately it isn’t, and I realize that implementing such change can
break backwards compatibility, so a completely backwards-compatible
workaround would be to implement this service I’m talking about.

If I’m not mistaken, the security issue already exists, since I can
reproduce exactly the same behavior today using approach described in the
first code snippet above. Unfortunately this workaround is ugly and logs
errors every time it is used.

All I want to know is whether the thing exists-and-visible, so that I can
safely display it in a mashup. I don’t care whether it does not exist at
all or just not visible, since I can’t use it in either case anyway.

It would be great if someone can retest and confirm it, since I did only a
couple of simple checks myself.

/ Constantine
Constantine
16-Pearl
Apparently it now works as expected in 8.5 (all versions), just received a confirmation. In the latest version "invisible" things resolve to null, exactly as we would like. This must be the shortest-lived idea, sorry :) / Constantine
geva
14-Alexandrite

Shortest lived perhaps, and best described and documented!

cbaldwin
13-Aquamarine
Status changed to: Archived

Seems to be working in latest versions as expected.

olivierlp
Community Manager
Status changed to: Delivered

8.5