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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.