How to perform dynamic connection in JavaScript embedding?
We have the option to perform dynamic connections in JavaScript embedding. The Dynamic Connection String feature enables you to modify the connection string of the data sources in dashboard view mode. This feature allows you to view the dashboard with a modified connection string on the Bold BI application itself and also on the dashboards embedded using the Dashboard Embedding feature as well.
How the Dynamic Connection String Works:
While creating live mode connections, you need to configure a Web API that will return the modified connection string. On dashboard rendering, the configured API will be triggered for each data source created with Dynamic Connection String Configuration. Based on the response from the API the connection string will be updated in the data source and the dashboard will be rendered. If the API is not reachable or if the API returned any errors then the dashboard will be rendered with an error stating that the connection is not valid.
To configure the Dynamic connection in Bold BI server level refer to the help documentation.
- Create any live mode connection such as MSSQL, MySQL, PostgreSQL etc.
- In the connection input form, click the Dynamic Connection String switch to enable the Dynamic Connection String feature for the data source.
- Click the Configure button to open the Dynamic Connection Configuration dialog.
- In the Dynamic Connection Configuration dialog, by default, External API will be selected. Fill the form for the Web API and click Save. The API will be validated by triggering the API with a Head request. Make sure that the provided API has HTTP HEAD method support. I have provided the URL value since in an upcoming topic we will have a sample that will run the in above mentioned.
- At the bottom of the dialog, there is an option pinned to choose the Configuration Mode and User Identity for the Dynamic Connection Configuration.
Configuration Mode:
The mode in which the Dynamic Connection String should function also can be used to limit the functionality to the embedded application or within the server or both.
mode | Functionality |
---|---|
Embedding | Allows to render the dashboards with modified connection string only when the dashboards are embedded using the Dashboard Embedding feature |
Server | Allows to render the dashboards with modified connection string only on Bold BI application itself |
Both | Allows to render the dashboards with modified connection string on both Bold BI application and dashboards embedded using the Dashboard Embedding feature as well |
User Identity
The Identity should be passed to the Custom Web API, in order to enhance the usage of the modified connection string at run time. This can hold the logged-in user information as Email and Full Name. After saving the configuration, complete the data source creation. To add the custom attribute in dynamic connection refer the custom attribute in dynamic connection string.
Steps to enable dynamic connection strings in embedded dashboards:
-
Download the Dynamic Connection Web API sample from GitHub and provide the mandatory details mentioned below by referring to the help documentation. In the sample by default we have the parameter used for microsoft SQL. You can refer the help documentation link for parameters to be included different data sources.
header | header |
---|---|
requiredParams | Comma separated values. The API should return the value with the keys mentioned in the argument.Eg: MSSQL required Parameters for the connection string are DataSource, InitialCatalog, Username, Password, IntegratedSecurity,AdvancedSettings, CommandTimeout, Schema |
datasourceName | Name of the data source |
datasourceId | GUID of the data source as string. |
customIdentity | The string value that holds the user identity information based on the identity type chose on Dynamic Connection String Configuration. Also it can be override while the dashboard embedded using the Dashboard Embedding feature |
identityType | The string value that holds the type of the user identity chose on Dynamic Connection String Configuration either Email or Full Name . Also it should be Custom while custom identity is passed on dashboard embedded using the Dashboard Embedding feature |
- Once you run the Web API, now create a dashboard with the data source created using the dynamic connection. For demonstration purposes, I have created two users (test1@test.com and test2@test.com) and configured the database using a dynamic connection. to switch between the database using the user email in JavaScript embedding, you need to enable the dynamic connection string API in BoldBI.create() method of JavaScript application like below.
var dashboard = BoldBI.create({
dynamicConnection:{
isEnabled:true,
identity:"test1@test,com",
}
});
dashboard.loadDashboard();
-
When I rendered the dashboard with the email: test1@test.com, the respective dashboard image is shown below,
-
When I rendered the dashboard with the email: test1@test.com, the respective dashboard image is shown below,
Additional reference:
- For configuring Dynamic connection in Bold BI server
- How to use Custom Attribute in Dynamic Connection String?
- How to pass the Custom Identity to the viewer Service?
- Dynamic Connection String Configuration within same Database
- Custom Attribute support for Dynamic Connection string
- How to perform JavaScript embedding?