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  

How to get the datacollector date in automation scripting.

Richard Moreau
Tera Contributor

Hi all,

 

I'm trying to create a daily snapshot of my backlog tickets and with pain and suffering I finally got this code to almost work:

 

(function(dataCollector) {
    var count = 0;

    // Test date
    // var scoreDate = new GlideDateTime('2025-02-05 00:00:00');

    // Get the collection date
    var scoreDate = dataCollector.getScoreDate();
    var scoreDay = new GlideDateTime(scoreDate.getDisplayValue().split(" ")[0] + " 00:00:00");
    var endOfDay = new GlideDateTime(scoreDate.getDisplayValue().split(" ")[0] + " 23:59:59");

    // --- Closed late on this day ---
    var closed = new GlideRecord('incident');
    closed.addQuery('active', false);
    closed.addQuery('closed_at', '>=', scoreDay);
    closed.addQuery('closed_at', '<=', endOfDay);
    closed.query();
    while (closed.next()) {
        var slaDueStr = closed.sla_due.getValue();
        if (!slaDueStr) continue;

        var slaDueDT = new GlideDateTime(slaDueStr + ' 23:59:59');
        if (closed.closed_at.getGlideObject().compareTo(slaDueDT.getGlideObject()) > 0) {
            count++;
        }
    }

    // --- Still open and overdue as of this day ---
    var open = new GlideRecord('incident');
    open.addQuery('active', true);
    open.addQuery('sla_due', '<', scoreDay.getDate()); // Compare against date only
    open.query();
    while (open.next()) {
        count++;
    }

    answewr = count;
})(dataCollector);

 

The issue is that I can't get the datacollector score date. Tryed so many ways without any luck.

 

This line is the issue: 

 

    var scoreDate = dataCollector.getScoreDate();

 

Here are my questions:

 

  1. How to pass the datacollector scoredate in an Automation Script that is attached to an indicator.
  2. Am I adrressing this the right wway? Is there an easier way.

Let me know thanks.

 

#Yokohama

1 REPLY 1

pavani_paluri
Tera Guru
Tera Guru

Hi @Richard Moreau ,

 

There is a typo error in your last line: 

answewr = count;

 it should be answer = count.

 

Your approach is good. As far as I know dataCollector.getScoreDate() — only works inside PA indicator scripts.

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P