Defining Global Functions
Overview
The BDB Dashboard Designer supports advanced customization using JavaScript. You can enhance dashboards by:
Using the built-in SDK methods library.
Writing custom JavaScript code tailored to specific use cases.
This makes dashboards more interactive and flexible, allowing for business-specific logic and presentation.
Why Use Global Functions?
In BDB, there's a designated script area called the Dashboard Script Area. This area is used to:
Initialize scripts before the dashboard loads.
Define global functions that can be reused throughout the dashboard.
Functions defined in component or connection script areas are limited in scope and cannot be reused elsewhere.
How to Define a Global Function
Global functions are defined using the window object. This ensures they are accessible across the entire dashboard.
Example
window.numberWithCommas = function(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};What does it do?
This function formats a number with commas as thousands separators (e.g., 1000000 becomes 1,000,000).
Where Can You Use Global Functions?
Once defined in the Dashboard Script Area, the global function can be reused in:
Component Script Areas
Connection Script Areas
Any other script context within the dashboard
Best Practices
Only define functions globally if they need to be reused across multiple areas.
Use clear, descriptive names to avoid conflicts with other functions or SDK methods.
Group related utility functions together for better organization.
Avoid polluting the global namespace with too many functions.
Last updated