Search code examples
thingsboard

Display assigned customer title in Thingsboard Alarm widget


For a tenant dashboard, we would like the alarm widget to display a device's assigned customer title as a data field.

My current workaround is to use a Cell Content Function to retrieve the customerId from the alarm object (alarm.customerId.id) and statically translate this to a title string. As far as I can tell, using the customerService to dynamically look up the customer title via the async getCustomer API call is not possible nor a good idea in a Cell Content Function.

A couple of options I have thought of without creating a custom Alarm Widget are:

  1. Use the Customer Details rule chain to fetch and store the title in the alarm details. Add the title from the alarm details as a data source. The downside is that I will need to move numerous alarm rules from the device profile to a custom rule chain.
  2. Use the Entity Assigned event in the rule chain to store the assigned customer title as a device timeseries or attribute. Add the assigned customer title timeseries / attribute as a data source. I suspect a side effect is that this will display the title as was last assigned to the device rather than when the alarm was created. Typically devices are not reassigned nor customer names modified so I see minimal downside here.

Any other thoughts or suggestions would be most appreciated!


Solution

  • When I have a list of devices in tenant dashboard, I had same question to get their customer name.

    I did the following steps and I have tested that it also works with the alarms:

    Open your alarm widget, select action window (the last one) and add a action with origin "on row click"(https://thingsboard.io/docs/user-guide/ui/widget-actions/#3-on-row-click) and type "Update current dashboard state" (https://thingsboard.io/docs/user-guide/ui/widget-actions/#update-current-dashboard-state).

    Back to you dashboard, open edit mode and add a alias with name "owner" (or whatever you want) and type "Owner of entity from dashboard state" (https://thingsboard.io/docs/user-guide/ui/aliases/#alias-types)

    Create a new entity admin widget in your dashboard (https://thingsboard.io/docs/user-guide/ui/widget-library/#entity-admin-widgets) and select the alias that you have created before (you dont need to put any keys).

    Save all, now when you click on your alarm widget's row, the entity admin widget will display your clicked alarm's customer name(since you already have the customer entity, you can also show other information of this customer).