Thingworx: Role-based Widget Visibility

Scenario: A widget should only be visible to members of the administrators group. Implementation should be a simple, reusable service that maps to any member of administrators as group membership changes.

A service can be written that can iterate over the groups that the current user is a member of, and search for a match to any group name:

var currentUserGroups = Resources["CurrentSessionInfo"].GetCurrentUserGroups();
var isAdmin = false;

for (var x = 0; x < currentUserGroups.length; currentUserGroups++) {
    result = currentUserGroups[x].name;
    if (currentUserGroups[x].name == "Administrators"){
          isAdmin = true;

result = isAdmin;

Note that because GetCurrentUserGroups is a property of CurrentSessionInfo, we are implicitly examining the user groups that the current user belongs to.

This service will return “true” if the user is a member of administrators. It is important to set the Boolean response to an affirmative response to the service name for clarity. Avoid negatives like “IsNotAdmin” because the response “true” would mean they are not something.

In order to change the visibility of a widget, the Boolean value needs to be flipped so that visibility=false. Use an expression function to do this explicitly. A name such as widgetVisibility is better than a name that indicates if the response is true or false. The input to the expression can be either true or false, so the result is not determinate.

Thingworx Mashup Builder

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha loading...

This site uses Akismet to reduce spam. Learn how your comment data is processed.