0

I am trying to add a "When" condition to a custom insights widget so that the widget is only visible on a dashboard for a specific database.

The problem is that the documentation for this doesn't cover the possible conditions and values available: https://learn.microsoft.com/en-us/sql/azure-data-studio/tutorial-build-custom-insight-sql-server?view=sql-server-ver15

The top part of the JSON code I have so far for this widget it is:

 {
            "name": "Import Queue",
            "when": "database=MyDB1",
            "gridItemConfig": {
                "sizex": 2,
                "sizey": 2
            },

But the condition "database=MyDB1" or "database==MyDB1" isn't working. I suspect that's because I have set the value for this condition wrongly, but can't find an example of how to use this condition.

Can anyone suggest what I need to place for the "when" condition to only show for the specific database MyDB1?

Update Oct 2021 I have since discovered on the Azure Data Studio GitHub wiki (https://github.com/microsoft/azuredatastudio/wiki/Contribution-points) that the format requires the parameter to be in single quotes. An example contained in this wiki is as follows:

"when": "connectionProvider == 'MSSQL' && !mssql:iscloud"

Applying this to my problem, I changed it to:

"when": "database == 'MyDB1'"

But this still didn't work. I suspect that database isn't the correct parameter name, so will keep searching. the official Microsoft documentation still hasn't been updated as yet.

Further Update There is now finally a solution for this, which I have placed in the answers below (https://stackoverflow.com/a/69632460/7858451).

Joe
  • 616
  • 2
  • 12
  • 27

1 Answers1

0

After much digging around on Azure Data Studio GitHub repository, I finally came across this wiki: https://github.com/microsoft/azuredatastudio/wiki/Context-Variables

This says for context variables:

databaseName - A string of the database name of the current connection. Ex. databaseName == 'master'

So it was databaseName that I was after all this time, plus the parameter value needed to be in single quotes.

Which means, by changing the configuration file JSON to the following:

 {
     "name": "Import Queue",
     "when": "databaseName == 'MyDB1'",
     "gridItemConfig": {
     "sizex": 2,
     "sizey": 2
 },

It finally hides the dashboard for all databases than the one specified.

Joe
  • 616
  • 2
  • 12
  • 27