Automatic update of Dashboard data

Question

How can I enable automatic update of data in dashboards?

Answer

For version 7.6.Х, you cannot enable automatic data update on customer level, but you can subscribe to ReloadDashboard notifications available for all dashboard widgets.

Create your own module without a parent object, e.g.,UsrDashboardHelper and add ReloadDashboard in messages (Direction: Publication, Mode: Address)

The possible implementation code of event generation might look as follows:

define("UsrDashboardHelper", ["ext-base", "terrasoft", "sandbox"], function(Ext, Terrasoft, sandbox) {
   var getView = function() {
      var config = {
         id: "UsrDashboardHelper",
         selectors: {
            wrapEl: "#UsrDashboardHelper"
         },
         items: []
      };
      return Ext.create("Terrasoft.Container", config);
   };
   return {
      timerId: 0,
      myTimer: function() {
         console.log("tik");
         sandbox.publish("ReloadDashboard", null, ["SectionModuleV2_UsrAutomobileSectionSectionDashboardDashboardModule"]);
      },
      init: function() {
         console.log("UsrDashboardHelper is on in: " + sandbox.id);
         this.timerId = setInterval(this.myTimer, 30000);
      },
      render: function(renderTo) {
         var view = getView();
         view.render(renderTo);
      },
      destroy: function() {
         console.log("UsrDashboardHelper is off!");
         clearInterval(this.timerId);
      }
   };
});

After you create the module, you can add it as a widget in the dashboard settings, which will result in the code exectution on the page. Such implementation will update all page widgets that have subscription to the ReloadDashboard event and are located in the sandbox specified as the third parameter in the sandbox.publish(...) method every 300000 milliseconds (5 minutes).

The sandbox Id of your dashboard page can be viewed as the "sandbox.id" value in the subscription method of all "widgets" to the "ReloadDashboard" event by putting a breakpoint in the DashboardModule.js module in the following string:

sandbox.subscribe("ReloadDashboard", this.onReloadDashboard, this, [sandbox.id]);

 

Like 0

Like

Share

4 comments

Hello Kobizka,



Our requirement is to update the dashboard data automatically for a specified time interval. I have created the module as you mentioned above and tried to add it as a widget in the dashboard by Referring: https://academy.creatio.com/documents/technic-sdk/7-16/adding-custom-dashboard-widget.



But I am getting error in Console stating that,



I haven't made any changes to the module code as you mentioned.



Also, you stated that subscribing to ReloadDashboard will update data for all page widgets .Does this page widgets includes Chart,Metrics,List,Widget,Gauge,Pipleine etc.. which are available in dashboards or just the Widget alone. If this can be applicable to all dashboard entities(Eg: Chart,Metrics etc..) how could I subscribe to Reloaddashboard. If any of those entities created in the dashboard their respecive pages are not getting appended to the current package.I tried to find their .js files by inspecting the elements but I couldn't get the page. Does, they have seperate .js files for each dashboard creation. If so where would be stored? 

Kindly, help me in solving this issue.



Regards,

Adharsh S

Dear Adharsh,

 

In order to implement the required functionality please do the following:

1. Create a module according to the article by the link below:

 

https://community.creatio.com/articles/automatic-update-dashboard-data

 

Please don’t forget to change the value of the third parameter of the “sandbox.publish” method call to the appropriate sandbox id of your dashboard page. You can find the information about how to determine the sandbox id of the dashboard page in the article by the link above. In my case, I want to implement automatic update of data in the “Employees” dasboards. Therefore, I change the value of the third parameter to the following:

 

myTimer: function() {

            console.log("tik");

            sandbox.publish("ReloadDashboard", null, ["SectionModuleV2_EmployeeSectionSectionDashboardDashboardModule"]);

        },

 

2. Add this module as a widget in the dashboard settings. Please see the screenshot below:

 

 

3. As a result, all dashboard widgets such as Chart, Metrics, and List etc. that have subscription to the “ReloadDashboard” message and are located in the sandbox specified as the third parameter in the “sandbox.publish” method will be automatically updated after a certain period of time.

 

I implemented this functionality on my local instance and it works perfectly. If you face some issue during the developing, please feel free to debug the client code in order to resolve the issue.

 

Best regards,

Norton

Hi Norton,



I have created a custom Dashboard "StatusDashboard" and got its sandbox id and passed as the 3rd argument of sandbox.publish() in the module. The sandbox-id passed is: "SectionModuleV2_UsrProfile1SectionSectionDashboardDashboardModule".

I have debugged the client code and found that the subscribe message "ReloadDashboard" in the DashboardModule is not called.

Got error in the console,



On reloading the dashboard page, I have debugged the DashboardModule page and found that sandbox-id recieving at subscribe message end is "SectionModuleV2_UsrProfile1SectionSectionDashboardDashboardModule" same as that we passed in the sandox.publish() Still the breakpoint is not hitting at the sandbox.subscribe() end.

Kindly, do the needful.



Regards & Thanks,

Adharsh S

Dear Adharsh,

 

In order to resolve the issue please add the “ReloadDashboard” message to the “Messages” list of the “UsrDashboardHelper” module:

 

 

Best regards,

Norton

Show all comments