Performance Analytics Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2024 07:59 AM - edited ‎08-22-2024 04:06 PM
Why does this PA script result in an error?
var gr = new GlideRecord('change_request_metric');
gr.addEncodedQuery('chg_closed_atONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()^mi_value=Normal');
gr.query();
var count = 0;
while(gr.next())
{
var activatedDate = new GlideDateTime(gr.mi_start);
var plannedStartDate = new GlideDateTime(gr.chg_start_date);
var adjustedplannedStartDate = new GlideDateTime(gr.chg_start_date);
//adjustedplannedStartDate.addDays(-10);
if(activatedDate > adjustedplannedStartDate)
{
count++;
}
}
If you comment out 'if(activated > adjustedplannedStartDate), the job completes successfully.
Here is the script I created in Fix scripts. This script contains a lot of gs.prints. And it works all the time.
var gr = new GlideRecord('change_request_metric');
gr.addEncodedQuery('chg_closed_atONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()^mi_value=Normal');
gr.query();
var count = 0;
while(gr.next())
{
var activatedDate = new GlideDateTime(gr.mi_start);
//gs.print("Activated Date is " + gr.mi_start);
//gs.print("var activatedDate is " + activatedDate + " is Actual Start Date");
var plannedStartDate = new GlideDateTime(gr.chg_start_date);
//gs.print("Planned Start Date is " + gr.chg_start_date);
//gs.print("var plannedStartDate is " + plannedStartDate + " is Planned Start Date");
var adjustedplannedStartDate = new GlideDateTime(gr.chg_start_date);
//adjustedplannedStartDate.addDays(-10);
//gs.print("Adjusted Planned Start Date is " + adjustedplannedStartDate);
//gs.print("var adjustedplannedStartDate is " + adjustedplannedStartDate + " is Adjusted Planned Start Date");
if(activatedDate > adjustedplannedStartDate)
{ count++;
gs.print("Activated is > than Planned");
gs.print("Count is " + count);
}
else
{gs.print("Planned is > than Actual.");
gs.print(count);
}
//gs.print("Change Request Number is " + gr.chg_number);
//gs.print("Planned Start Date is " + gr.start_date);
//gs.print("Actual Start Date is " + gr.work_start);
//gs.print("Change Request Number is " + gr.chg_number);
}
gs.print("Count of records is " + count);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2024 11:26 AM
I went a different direction with similar results. The script starts by determining the records that meet the time demands, and these are written into a filter condition statement. This filter condition is used to create a recordset. I'm then using glideaggregate to group by either number or sys_id.
Here's my latest script:
var gr = new GlideRecord('incident_metric');
gr.addEncodedQuery('mi_definition=39d43745c0a808ae0062603b77018b90^inc_resolved_atONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()^inc_resolved_atONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()^mi_endISNOTEMPTY');
gr.query();
var incCount = 0;
var incFilterCondition = "numberIN";
while (gr.next()) {
var activatedDate = new GlideDateTime(gr.mi_end);
var adjustedplannedStartDate = new GlideDateTime(gr.mi_start);
adjustedplannedStartDate.addSeconds(70);
if (activatedDate >= adjustedplannedStartDate) {
incCount++;
if (incCount < 2) {
incFilterCondition = incFilterCondition + gr.inc_number;
} else {
incFilterCondition = incFilterCondition + ',' + gr.inc_number;
}
}
}
getCount();
function getCount() {
var incidents = 0;
var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT','sys_id');
ga.addEncodedQuery(incFilterCondition);
ga.query();
if (ga.next())
incidents = ga.getAggregate('COUNT','sys_id');
return incidents;
}
This script completes without any errors. The score is always 1, but the show records has the correct records and count.
I've tried everything to alter what the score is, but can't get it to work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2024 08:41 AM
Hello all,
I still have no solution for this problem.
While attending a SN Platform Analytics Academy, it was mentioned to tag a SN employee so they can provide input on this post. How do I tag a SN employee?
Let me restate what I'm trying to do. I'm looking for Change Requests where the Actual or Start Date is greater than 30 minutes of the Planned Start Date. Since my customer is stating 30 minutes, I cannot use a standard filter condition. The smallest time element for the filter condition is 1 hour. I've tried .5 hours, and it does not work.
So I have to write a script that has a function to determine the records where the actual start date is greater than the planned start date by at least 30 minutes. I do not need the calculated duration for anything. I only need the list of records.
And this is my problem, how do i determine the records based on the results of a function.