Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

How to show exact supporting records for scripted SAM KRI manual indicators

pavan Punna
Tera Contributor

We calculate three SAM KRI scores by grouping eligible Software Discovery Models into unique Product and Edition combinations and matching them against version-independent Software Models.

The calculation requires cross-table matching and duplicate handling, so a Script Include writes the results to three manual PA indicators. The scores and dashboard are working, but Show Records is unavailable because the manual indicators do not contain supporting record snapshots.

We need users to select each metric and see the exact unique records contributing to the score. For example, a Product Owner score of 7 should drill down to exactly those 7 unique products.

Is there a supported method to associate supporting records with scripted manual scores, or to use an automated or scripted indicator source that collects one record per unique Product and Edition combination without creating a custom detail table?

1 REPLY 1

vijaydodla
Giga Guru

Hi @pavan Punna -

 

If you are building complex metrics in ServiceNow Performance Analytics such as cross-table matching or grouping unique combinations you have likely discovered that Manual Indicators do not support the "Show Records" drill-down functionality. Because manual indicators don't utilize the pa_snapshots table, there are no underlying records to display.

 

Furthermore, if you try to use an Automated Indicator with a "Count Distinct" aggregation, the score will be correct, but clicking "Show Records" will display all the underlying records that contributed to the count, not just the unique ones.

 

in your case I think you can achieve a perfect 1:1 match between your score and your drill-down records by using an Automated Indicator paired with a Script Include in the Indicator Source condition. By using the javascript: syntax, you can pre-filter the exact unique records before the PA engine collects them, completely bypassing the need for custom detail tables or manual indicators.

 

Here is an example - Calculating Software Asset Management KRI scores. You need to group eligible Software Discovery Models into unique Product and Edition combinations. If your unique count is 7, your Product Owners expect to click that score and see exactly 7 unique records.

Here is the step-by-step guide on how to architect this solution.

 

Step 1: Create the Script Include

Instead of relying on PA to do the deduplication, we will use a Script Include to do the complex cross-table matching and duplicate handling.

Create a client-callable Script Include (or one accessible by the System user). This script will query your table, group the records by your unique criteria, select exactly one representative sys_id for each unique group, and return them as a comma-separated string.

javascript
 
See below code works for you ..you might need to tweak it as needed. But I hope this might help you to move forward. 
var SAMKRIRecordHelper = Class.create();
SAMKRIRecordHelper.prototype = {
    initialize: function() {},

    getUniqueDiscoveryModels: function() {
        var uniqueSysIds = [];
        
        // 1. Query eligible Software Discovery Models
        // 2. Match against version-independent Software Models
        // 3. Group by Product + Edition
        // 4. Push exactly ONE sys_id per unique group into the array
        // (Insert your GlideAggregate or GlideRecord logic here)
        
        return uniqueSysIds.join(','); 
    },
    type: 'SAMKRIRecordHelper'
};

 

Step 2: Configure the Indicator Source - This will be the filter

Next, create a new Indicator Source pointing to your target table (e.g., Software Discovery Models). Instead of standard condition builder rules, we will call our script.

  • In the Conditions builder, set the filter to: [Sys ID] [is one of] [javascript:new SAMKRIRecordHelper().getUniqueDiscoveryModels()]

Developer Warning: The PA Data Collector job runs in the background as the "System" user. Ensure your Script Include does not rely on session-specific data like gs.getUserID(), as it will not evaluate to the user viewing the dashboard.

 

Step 3: Configure the Automated Indicator - This acts as the collector

Finally, set up your Automated Indicator to collect the data.

  • Link it to the new Indicator Source you just created.
  • Set the Aggregate to Count (Do NOT use Count Distinct, as your script has already done the deduplication!).
  • Check the Collect records checkbox on the indicator form.

 

So, when the PA Data Collector job runs, it evaluates the Indicator Source condition first. Your script executes and hands the PA engine an exact list of 7 sys_ids. PA counts these 7 records, generates a score of 7, and saves those exact 7 records into the pa_snapshots table.

 

When your users click "Show Records" on the Analytics Hub or Dashboard, they get exactly what they asked for: the exact unique records contributing to the score, with no duplicates and no custom tables required.

 

Please ACCEPT the solution if above response helped you to resolve the issue. Thank you !