- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 02:12 AM
Hi Guys, I am pretty new to PA and very new to scripting. I am looking to exclude weekend from the formula indicator.
I guess I have to include GlideSchedule in the script but how?
Current OOB script:
var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};
var days=function(x,y){return diff(x,y)/(24*60*60*1000);};
days(current.opened_at, score_end);
Solved! Go to Solution.
- Labels:
-
Performance Analytics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 04:17 AM
The indicator is probably for triggering action on aging tickets.
I would not recommend looking at schedules, as things might get complex and hard to maintain.
Below script should exclude saturdays and sundays from the daycount.
Please try and let me know if it works
var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};
var businessDays = function(x,y){
var xx = new GlideDateTime(x);
var startDayOfWeek = xx.getDayOfWeek(); //11 = monday 7 = sunday
var ageDays = Math.floor(diff(x,y)/(24*60*60*1000)) || 0; //total day age
var withoutFullWeekendDays = ageDays - (Math.floor(ageDays / 7) *2); //for full weeks substract 2 days per week
var modDays = ageDays % 7; //remaining non full week days
var substractDays = Math.min(Math.max(0,(startDayOfWeek - 5) + modDays),2); // should work, between w2 days substract
return ( withoutFullWeekendDays - substractDays ) || 0;
};
businessDays(current.opened_at, score_end);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 04:17 AM
The indicator is probably for triggering action on aging tickets.
I would not recommend looking at schedules, as things might get complex and hard to maintain.
Below script should exclude saturdays and sundays from the daycount.
Please try and let me know if it works
var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};
var businessDays = function(x,y){
var xx = new GlideDateTime(x);
var startDayOfWeek = xx.getDayOfWeek(); //11 = monday 7 = sunday
var ageDays = Math.floor(diff(x,y)/(24*60*60*1000)) || 0; //total day age
var withoutFullWeekendDays = ageDays - (Math.floor(ageDays / 7) *2); //for full weeks substract 2 days per week
var modDays = ageDays % 7; //remaining non full week days
var substractDays = Math.min(Math.max(0,(startDayOfWeek - 5) + modDays),2); // should work, between w2 days substract
return ( withoutFullWeekendDays - substractDays ) || 0;
};
businessDays(current.opened_at, score_end);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 08:55 AM
Have you tried if this solution works for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2017 09:18 AM
Work like a charm! Thanks for the solution. Much appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 02:47 AM
Hello,
I have tried the above solution but unable to get the records displayed in the widget of the dashboard. Since you have mentioned that the above solution worked for you, could you please post the detailed execution of that solution along with the screenshots and how and where(like in indicator or breakdown etc..)you have used the above script and was able to get the records based upon their age excluding weekends.
Thanks and Regards,
Nasreen