Hello,
There are two different fields in your ticket, the date/time fields, and the calculated fields, the invalid dates and weekends are related only to the date/time fields, and not the calculated ones, so, you should check the weekends from the equation.
For example, if the date/time field is the fieldname1, and the fieldname2 is an number field for the number of days, the equation associated to the calculated field would be similar to:
(function(){
var d = new Date(fieldname1*86400000), c = 0;
while(c < fieldname2)
{
d.setDate(d.getDate()+1);
if(d.getDay() != 0 || d.getDay() != 6) c++;
}
return CDATE(FLOOR(d/86400000), 'mm/dd/yyyy');
})()
If you need additional help implementing your project, I can offer you a custom coding service through my personal website:
http://cff.dwbooster.com/customization
Best regards.
Thanks for your speedy reply.
The code above works …. that is to say it will produce the new date
That is new date – or + (fieldname value) = new date
The new date takes into account the fact that weekends are invalid so does not add them to the count…..however, it still counts the invalid dates that I have set.
How can I make sure that the invalid dates are treated just like invalid weekends (as ticked in the field settings) during a calculation?
Thanks
Hello,
As I said previously the equations are independent of the date/time fields, even if you are assigning the calculated date to the date/time field programmatically (the equation associated to the calculated field is who determines the next date). So, in the previous equation, you should check the date against the list of invalid dates, for example, if the invalid dates are:
07/23/2017 and 09/30/2017
The piece of code:
if(d.getDay() != 0 && d.getDay() != 6) c++;
should be modified as follows:
if(d.getDay() != 0 && d.getDay() != 6 && jQuery.inArray(CDATE(FLOOR(d/86400000), 'mm/dd/yyyy'), ['07/23/2017', '09/30/2017']) == -1) c++;
Best regards.