Scripted PA indicator for open records

Leonel Sandroni
Tera Guru

Hi there,

I'm working with a customer requirement. They need a performance analytics indicator in order to count open demands for everyday. It should build a trend chart where any point is the count of the new demands in every day. For example, if we created 2 new demands on wednesday, 3 yesterday and 4 on today, the PA indicator should show 2-3-4 in the trend.

I have tried to build it with the pre-configuration filters but I haven't had good results because everything I do will always add up the data (2-5-9). It seems it's not possible to make it with filter conditions so...I'm thinking to get it with an scripted indicator but I don't know how to build the basic jscript structure.

LeonelSandroni_0-1701453059141.png

 



Do you have any suggestion?

Thanks!!!

2 REPLIES 2

Dan Covic2
Tera Contributor

Maybe this could be a good start:

 

// Your script for the Open Demands Count indicator
(function runScript(source, map, log, target /*undefined onStart*/ ) {
    // Set the target table
    var table = 'your_demand_table'; // Replace with your actual table name
    
    // Create a GlideAggregate to count open demands
    var ga = new GlideAggregate(table);
    ga.addQuery('state', 'in', 'New, In Progress, On Hold'); // Adjust states as per your requirement
    ga.addAggregate('COUNT');
    ga.groupBy('opened_at'); // Group by opened_at field

    // Execute the query
    ga.query();

    // Iterate through the results and set the values for the indicator
    while (ga.next()) {
        var date = ga.getValue('opened_at');
        var count = ga.getAggregate('COUNT');
        
        // Set the value for the indicator
        target = date + ':' + count;
    }
})(source, map, log, target);

AndersBGS
Tera Patron
Tera Patron

Hi @Leonel Sandroni ,

 

You requirement is quite easy without any automated scripted indicator. If you just create a daily indicator source based on the demand table, you will be able to capture 2-3-4 instead of 2-5-9. Remember the condition in the indicator source should contain "created on today" - otherwise it will not work.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/