Need help to exclude weekends from the calculation

MR1
Tera Contributor

Hi All,

 

The below script is working as expected but I need help to modify and remove the weekend from the calculation.
The below advance script is on the calculated tab of field "Aging". The integer type field 'aging' is on scoped application. 

 

(function calculatedFieldValue(current) {

	if(current.state == 7){ //7 is closed value of state field on a scoped application
		var aging= GlideDateTime.subtract(new GlideDateTime(current.sys_created_on),new GlideDateTime(current.closed_at));
	} else {
		aging= GlideDateTime.subtract(new GlideDateTime(current.sys_created_on),new GlideDateTime());
	}

	return aging.getDayPart();

})(current);

 

1 ACCEPTED SOLUTION

@MR1 

I'm not sure  how you added my code to you instance , I tried and it  works well. 

See my pics below.

 

 

 

start end and  agingstart end and agingCalculation scripts on field  "Aging"Calculation scripts on field "Aging"test1test1test2test2

Please mark my answer as correct and helpful based on Impact.

View solution in original post

10 REPLIES 10

@MR1 

In my country holiday changes every year.....

I think you need a table to store the holidays,and get the holiday infomation from the table at the first. and modify the below part to judge if it's a holiday....

 

 

 if( startDateTime.getDayOfWeekUTC() == 6 || startDateTime.getDayOfWeekUTC() == 7){

 

Please mark my answer as correct and helpful based on Impact.