Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi all,
I have a set of things (collected in a infotable) and I would like to know if the current user logged has visibility for each thing in order to show just his thing.
I would like to avoid to use GetImplementingThing function because if I will have a large number of Thing, the service will respond slowly.
Please see code below:
for (var x = 0; x < listLength; x++) { var rowPos = list.rows[x]; var posInstance = Things[rowPos.PosThingName]; try { if(posInstance.name) { result.AddRow(rowPos); } } catch(err) { } }
This will work because the "posInstance.name" will return error
User does not have visibility permission for....THING_NAME
but this cause a large number of log error in monitoring and I would like to avoid that.
Is there a way to know if current user has visibility permission on a Thing?
Solved! Go to Solution.
You can use spotlightsearch instead (I don't know the performance...)
Istead of:
try { if(posInstance.name) { result.AddRow(rowPos); } } catch(err) { }
Use:
var any = Resources["SearchFunctions"].SpotlightSearch({ maxItems: 1, searchExpression: rowPos.PosThingName, types: { items: ["Thing"] } }); if (any.rows.length==1) { result.AddRow(rowPos); }
You can use spotlightsearch instead (I don't know the performance...)
Istead of:
try { if(posInstance.name) { result.AddRow(rowPos); } } catch(err) { }
Use:
var any = Resources["SearchFunctions"].SpotlightSearch({ maxItems: 1, searchExpression: rowPos.PosThingName, types: { items: ["Thing"] } }); if (any.rows.length==1) { result.AddRow(rowPos); }
I don't see why GetImplementingThings would be any slower, one way or another you are determining all potential Things and then pulling the ones that are visible.
Carles answer is correct. I've validated and implemented in my current project. The search services automatically determine user visibility and only return entities to which a user has access.
Because we will have different customer and each customer will have his own set of things that he will be able to see and on which I will have to performe research on the related stream.
This solution works but to increase performance I added a field in my infotable with unitVisibility then I have added a filter in my query specification