Dashboard and Gadgets
Enterprise Jira users often need to automatically generate dashboards with gadgets, to provide a consistent management-level overview of progress. These could be created either on demand, or automatically in response to version or project-created events.
Some gadgets take a JQL string, but others require a saved filter, so you may also need to generate one or more saved filters at the same time as creating a dashboard. Take care that you share both the dashboard and any dependent saved filters with your target users - in the example we share it globally.
The secret to perfecting this is (as always) to start small and work with a simple script in the Script Console. Once that’s working you can wire it to events such as version created/resolved etc using a Script Listener.
Start by creating a template dashboard using the normal UI. When you are happy you can run the following script, which will dump the configuration of the dashboard to the console. Make sure you start with only a single gadget to keep things simple.
Line 13: Change the dashboard ID to the one you want to inspect
Now, plug those values in to the script below, and execute:
Line 28: Shared globally, change to suit
Line 31: Sample query - you could plug in versions from a VersionCreated event for instance
Line 45: Numbers are column and row position
Line 49: User configuration for the gadget - take from the dumped configuration
Line 62: Generated search request
Line 69: Module key - empty for built-in gadgets
This will create a new dashboard with two configured gadgets. You should end up with a new dashboard:
Jira doesn’t like it if you generate multiple dashboards for the same user with the exact same name. When testing delete the dashboard after each run.