1

Does anyone have custom action Javascript code to navigate to new dashboard state on clicking different tooltips (map) of various devices of same devicetype which leads to different dashboard states.

IN MY CASE: I have three thermostats and I need to handle the actions on these three thermostates should open different dashboard states, however the device.type is same for all devices.(Thermostat)

I copied the code from Dashboard guide video part- 2 and just changed the variable "device.type to device.name" but it doesn't work. There should be another way of doing it with If conditions (Variable or Keyword that indicates specific device name).

I have also tried with 'entityName', 'device.entityName','device.Name', 'entityID', device.entityID etc. but nothing worked so far.

Custom action code:

var $injector = widgetContext.$scope.$injector;

$injector.get('deviceService').getDevice (entityID.id).then(function(device) {

      if (device.name == 'thermostat1') {                    

          openDashboardState ('Thermostat1');

      } else if (device.name == 'thermostat2') {

          openDashboardState('Thermostat2');

      } else if (device.name == 'thermostat3') {

          openDashboardState('Thermostat3');

      }

});

function openDashboardState(stateId) {

    var params = {
        entityId: entityId,
        entityName: entityName
    };

    Widgetcontext.statecontroller.openState(stateId, params, false);
}

I am a beginner in Javascript & Front-end development. Could any JS developer or expert in Thingsboard help me out? It would be great.

Thank you in advance.

Best Regards,

Thangz

lupz
  • 3,620
  • 2
  • 27
  • 43
mukara
  • 97
  • 2
  • 14
  • Hi and welcome to SO! I guess we will need some more specificy on "it doesn't work" :) Are there any error messages in your browser's dev-tools log? By using the `deviceService` you are performing a http-request to the server. This might not be neccesary, as you might already have the device-data (they are displayed in your map) in the widget's datasources. – lupz Feb 12 '19 at 15:38
  • Hello, Actually there were some case sensitive mistakes in the JS code, which I have corrected and now it works perfectly. with 'device.name'. Thank you so much for your response. Regards,Thangz :) – mukara Feb 13 '19 at 09:07
  • I'm glad to hear that you found the issue! Happy coding! – lupz Feb 13 '19 at 09:20

1 Answers1

0

Finally it works with 'device.name' It was a typo mistake. Now, I found those case sensitive mistakes in code and corrected it.

Best Regards, Thangaraj

mukara
  • 97
  • 2
  • 14