Business duration SLA calculation in PA scripts

Krithika R
Tera Contributor

Hi,

I'm trying to calculate the SLA Duration for an indicator using a pa_scripts like below,

For eg: On 3rd April 2025,
1 day SLA will be calculated like sc_task which are created on 2nd April >5pm till 3rd April  <5pm
2 day SLA will be calculated like sc_task which are created on 1st April >5pm till 2nd April <5pm
3 day SLA will be calculated like sc_task which are created on 31st March >5pm till 1st April <5pm

Below is the pa_script I'm using

var res = '';
var sctskid = current.sys_id;

var today = new GlideDateTime();
var checkDay = today.getDayOfWeekLocalTime();
var dayOne, dayTwo, dayThree, dayFour;

if (checkDay == 1) {
    dayOne = -3;
    dayTwo = -4;
    dayThree = -5;
    dayFour = -6;
} else if (checkDay == 2) {
    dayOne = -1;
    dayTwo = -4;
    dayThree = -5;
    dayFour = -6;
} else if (checkDay == 3) {
    dayOne = -1;
    dayTwo = -2;
    dayThree = -5;
    dayFour = -6;
} else {
    dayOne = -1;
    dayTwo = -2;
    dayThree = -3;
    dayFour = -4;
}

var sla1 = new GlideDateTime();
sla1.addDays(dayOne);
var one = sla1.getDate();
gs.print("one " + one);

var sla2 = new GlideDateTime();
sla2.addDays(dayTwo);
var two = sla2.getDate();
gs.print("two " + two);

var sla3 = new GlideDateTime();
sla3.addDays(dayThree);
var three = sla3.getDate();

var sla4 = new GlideDateTime();
sla4.addDays(dayFour);
var four = sla4.getDate();

var oneStart = two;
var oneEnd = one;

// gs.log("Krithika 8 check Day " + checkDay);
 gs.log("Test sctask with 1 day sla " + oneStart);

var tsk3 = new GlideRecord("sc_task");
tsk3.addQuery('sys_id', sctskid);
tsk3.addEncodedQuery("sys_created_on>javascript&colon;gs.dateGenerate('" + oneStart + "','17:00:00')");
tsk3.orderByDesc('sys_created_on');
tsk3.query();

if (tsk3.hasNext()) {
    if (tsk3.next()) {
        //res = tsk3.sys_id;
        if (!gs.nil(tsk3.number.getValue())) {
            res = tsk3.number;
        }
    }
}
gs.log("final result "+res);
res;


Log values is populating with all the matching results from indicator source and automated indicator why? and also when I filter out the empty res values it is giving me 3 actual records for 1-day sla but the score which is getting stored in analytical hub is 7 how?

KrithikaR_0-1743672559171.png

KrithikaR_1-1743672765868.png
Analytical hub

KrithikaR_2-1743672909150.png

Scheduled data collection is a daily job and relative start, and end is at 1 day ago. I even tried 0 days, still it results in 7 on analytical hub. 
Not sure what is going wrong in the script. Please advise.
Thanks

 

 

 

2 REPLIES 2

Mark Manders
Mega Patron

What is the data you actually want to report?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark
I want to report the score as 3 in analytical hub