Jira KPI Metric Visualization Widget

I need help displaying a Jira KPI chart (total vs resolved). My updated query returns null unexpectedly. Here’s my revised code:

CustomQueryManager qm = CustomQueryManager.init();
Query base = qm.filterUnresolved().withinRange('now-15d', 'now-7d').build();
Long allIssues = searchHandler.countAvailable(currentUser, base);
Long fixedIssues = allIssues - searchHandler.countAvailable(currentUser, qm.applyResolvedFilter());

What is missing?

In my experience, one of the common issues with a code snippet like this is forgetting to apply the same time range filter to both queries. It appears that your “fixed issues” count isn’t using the withinRange filter that you defined in your base query. This mismatch can lead to unexpected null results when the second query isn’t bounded by the same time constraints as the first. In my setup, ensuring that each query is scoped properly to the intended date range solved similar issues. Double-check that your resolved filter query also includes that timeframe.

I encountered a similar hiccup in a project where the key issue turned out not to be the time filters, but rather the way the query object maintained its state across successive calls. Indeed, it is crucial to verify if the resolved filter is independently reinitializing the query state instead of building on the previous configuration. In my case, merging the query criteria into a single, cohesive query—thereby avoiding the risk of state reset—resolved the unexpected null values. Careful management of query state ensured that all necessary filters were retained.