How to output the actual database query of a dashboard element

1 post / 0 new
Anders
Anders's picture
How to output the actual database query of a dashboard element

Have you ever found yourself in need to get the actual database query of a certain visualization?

You could always pop up your favorite SQL Profiling tool but quite often, when you are at the customer site or somewhere without a decent range of tools available, you could always use JavaScript and the browser console.

If you are new to JavaScript and/or jQuery you should really do some tutorials and learn the basics of this language to get the most out of the AnalyzePRO platform!

About the script

The AnalyzePRO platform triggers a range of events. One of them, dataElementRendered, is triggered every time a visualization (of any type) is done rendering.
A handler for this event has the complete ElementResponse object available as a input parameter.

The ElementResponse has a property named Feedback which contains the complete query parsed for excution in the database.

So our script is quite simple: For each time a visualization is done rendering, we want to ouput the query to the browser console window.

Browser console
You open the browser console by hitting F12 (all browsers).

Dashboard debug mode
We only want to write to the browser console if the dashboard is in debug mode. You toggle debug mode of a dashboard with Crtl+D.
The console outputs "Enabled debug on page" once the dashboard is running in debug mode.

Once the dashboard is in debug mode, all dashboard events triggered will be reported to the console as well.
In this way you can set a dashboard in edit mode to learn which dashboard events are triggered when.

The function badebug.log() is a function for logging debug messages. Basically this function will write to the browser console if the dashboard is in debug mode.

/* jQuery document ready handler wraps eventhandlers*/
$(document).ready(function(){

  /* 
    dataElementRendered is handeled for all visualizations, 
    change from .elementContainer to #elContainer_2, 3, 4 etc 
    if you want to handle only one element 
    
    Have a look at http://services.businessanalyze.com/community/node/205 
    for details on custom events and container IDs
  */
  $("body").on("dataElementRendered",".elementContainer",function(evt,elRes){

    /* 
      elRes is ElementResponse, the dataobject returned from the server. 
      Output the feedback property to the console 
    */
    badebug.log("/* QUERY FEEDBACK: */\n\n" + elRes.FeedBack);
  });
});

Happy coding!

Tags: