Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Scripted Indicator scores repeating across breakdown elements

venori26
Tera Contributor

Hello Team,

 

I have written an indicator script but the scores are repeating across breakdown elements. the scores are showing correct if I individuation filter a query with an element of a breakdown. adding my script below. The script is about calculating 'past due days' of an incident category. Each category has multiple incidents and each incident has a resolution date.  So when I show past due days at category level, i need to pick the earliest due date among all the incidents of that particular category.  And then I subtract that date with the current day to get the number of past due days: How to address this issue? thanks in advance. 

 

(function() {
var ga = new GlideRecord('incident');
var now = new GlideDateTime();
//ga.addQuery('category','Hardware');
ga.orderBy('opened_at_date'); // earliest first
ga.setLimit 1); // only need the earliest
ga.query();

if (ga.next()) {

var minGdt = new GlideDateTime(ga.getValue('opened_at_date'));
var today = new GlideDateTime();
var diffDays = Math.floor((today.getNumericValue() - minGdt.getNumericValue()) / (1000*60*60*24));
return diffDays;
}
return 0;
})();

venori26_0-1757539398683.png

 

4 REPLIES 4

sizzleMcFace
Tera Guru

Could you check the pa_scores_l1 table, filtered for the Indicator & Breakdown in question and then post a screenshot of that list here? That would help to see what the issue is.

 

Thanks!

venori26
Tera Contributor

it just showed the score again while I was pulling data from scores table:)

venori26_0-1757948448867.png

 

From what I can see, the score is the same for each day for the same element, but the different element on the top also shows a different score. So based on just this, breakdown could be fine but your Indicator filtering could have issues.

 

Also, in your originally posted script there are some issues:

1. Missing "(" in setLimit

2. Variable "now" is not used anywhere.

3. Are you sure "opened_at_date" exists and works as you expect? I would use sys_created_on as that is a default field and also a datetime, not a date.

venori26
Tera Contributor

This issue is resolved. I wrote a simple indicator script and set the aggregate to minimum

 

var round_to_days= new GlideDateTime(current.calendar_duration).getNumericValue()/(1000*60*60*24);
round_to_days;