Exclude weekend from "Incident.Age.Days"

tsoct
Tera Guru

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);

1 ACCEPTED SOLUTION

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

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);


View solution in original post

11 REPLIES 11

Do you have any solution for excluding holidays along with weekends ?

No, but I was wondering if one was needed.