How to use Scripts?
BDB offers script support at the component level to display the intended UI actions and at the data connection level to apply data-related back-end changes.
The scripting mechanism makes the creation of complex dashboards easy and quick. The users require basic scripting knowledge to create dashboards using the BDB Designer module.
This section aims to provide a basic understanding of writing scripts and functionality.
Dynamic Visibility
The scenario is to have a checkbox that, when enabled displays a Column chart, and when disabled, shows an Area chart.
Navigate to the Designer canvas page for a dashboard.
Click the Component Library icon.
Drag and drop the Checkbox, Bar Chart, and Line Chart components into the canvas.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FJSjtOfYKUszowqe5PqJj%252Fimage.png%3Falt%3Dmedia%26token%3Ddacc1c71-e1ed-4cea-b10e-fa1cbeb1479a&width=768&dpr=4&quality=100&sign=5fb76e0d&sv=1)
Click on the Properties icon next to the Checkbox component.
Set Checked Value to ‘1’ and Unchecked Value to ‘0’ (as shown below) using the General properties tab of the Checkbox component.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FI5wAM00UhCbqO65yKNKM%252Fimage.png%3Falt%3Dmedia%26token%3D6da2a59a-d1a4-4019-99b6-ef8416ed15eb&width=768&dpr=4&quality=100&sign=9f981ed&sv=1)
Create data connections for the Column chart and Area chart. Refer to the Excel Connection page of the Establishing a Data Connection section for the details.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252Fm2nqEHXtYrXBF7FMTWey%252Fimage.png%3Falt%3Dmedia%26token%3Db96c679a-d907-4733-b37b-f1c59172f67b&width=768&dpr=4&quality=100&sign=e841e884&sv=1)
Click on the Script on Load icon provided next to the Checkbox component.
The script window for the Checkbox component opens.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FDvXhEecwU8qenjvkyGFY%252Fimage.png%3Falt%3Dmedia%26token%3D9676159e-29e7-4978-afff-7cdd40f0f143&width=768&dpr=4&quality=100&sign=2d0eb515&sv=1)
Write the relevant script for the action mentioned above, as explained in the following steps:
Write the if statement for the script following the order of “changedItem.attributes.Value”
Pass ‘Value==1’ (In other words, it suggests that the checkbox is enabled)
Either click the Help icon or use the Ctrl+Space keys to get assistance in writing the script.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FgrLqlOC9LGO8izQlVSLY%252Fimage.png%3Falt%3Dmedia%26token%3D07c5101e-378a-44ff-841a-73871bf3c742&width=768&dpr=4&quality=100&sign=128afe65&sv=1)
Please Note: The user can select the Hide Component and Show Component functions from the Scripting Help window.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FyrOf2fNFaG863rlw5r4c%252Fimage.png%3Falt%3Dmedia%26token%3D4807c6f3-0227-4cda-94c1-374887fab40f&width=768&dpr=4&quality=100&sign=10407e05&sv=1)
You can modify the readily available script with the below given steps:
Select the ‘Show and Hide’ function as per the requirement from the Designer Scripting Help window.
If the ‘Value == 1’ (in other words, if the Checkbox is enabled) the Bar chart should be displayed.
For this to occur, Place the Hide Component and Show Component functions under the if function.
Pass Bar chart value to the Hide Component function.
Pass the Line chart value to the Show Component function to make sure that the Column chart will be hidden when the Area chart is displayed.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FU7qJdJQyJ30zjhkDCLVH%252Fimage.png%3Falt%3Dmedia%26token%3Dbcf9684c-e13c-42e3-9bc1-9aa87918a96c&width=768&dpr=4&quality=100&sign=b017e1af&sv=1)
If the Value == 0 (in other words, if the checkbox is disabled), we need to do the reverse of the function that we used earlier. So that when users uncheck Check Box, the Line chart gets displayed and the Bar chart remains hidden.
To accomplish this, the users need to write the highlighted portion of the script:
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FDE8dGUqO62JDDi7EKyQq%252Fimage.png%3Falt%3Dmedia%26token%3D8bb9eeaa-410d-4b9a-a6a0-3f8102205282&width=768&dpr=4&quality=100&sign=a9a40443&sv=1)
After entering the above script successfully, click the Preview icon to view the results.
In the below screen capture, since the Checkbox is checked, the Column chart is displayed.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FSiJqaVGPRjd5ddj6UTb2%252Fimage.png%3Falt%3Dmedia%26token%3D0501289b-50b0-4217-8d5c-d4e1cfd2544c&width=768&dpr=4&quality=100&sign=e2b032f4&sv=1)
By unchecking the Checkbox displays the Area chart gets displayed.
![](https://docs.bdb.ai/~gitbook/image?url=https%3A%2F%2F859511478-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FGDmsjfjJBNqow7Fo97cO%252Fuploads%252FiSX0Ix2xrAIYzlCJ9y75%252Fimage.png%3Falt%3Dmedia%26token%3Db18b8935-ad62-4dbb-8046-e81e15694340&width=768&dpr=4&quality=100&sign=6139e24f&sv=1)