Business duration SLA calculation in PA scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 02:40 AM
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: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?
Analytical hub
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
- Labels:
-
Performance Analytics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 06:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 06:48 AM
Hi Mark
I want to report the score as 3 in analytical hub