Difference between revisions of "IsHoliday"
From SmartWiki
Line 23: | Line 23: | ||
In '''Expression''' section of the [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] you would call the function: | In '''Expression''' section of the [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] you would call the function: | ||
− | bus_date_subtract) | + | bus_date_subtract(); |
Note: The function definition can be changed to accept parameters (fields containing dates) that are passed at the time of calling the function from any [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]]. | Note: The function definition can be changed to accept parameters (fields containing dates) that are passed at the time of calling the function from any [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]]. | ||
[[Category:Custom Fields]][[Category:JavaScript]] | [[Category:Custom Fields]][[Category:JavaScript]] |
Revision as of 14:32, 21 September 2009
To subtract business days from a given date, the following code can be used in a Special Browser script field that will populate a Calculated Value Custom Field with the new date.
In the Special Browser script field you define the function that subtracts the a number of days from a given date
function bus_date_subtract() { var frm=document.forms[0]; var formatstr="dd/mm/yyyy"; var start=ConvertDateStr(frm.startdate.value,formatstr); var sub=-5; for(i=-1;i>sub;i--) { var cdate=dateadd(start,'D',i); if(!isHoliday(cdate)) sub--; } document.frmevent.cf_1742956 .value=cdate; }
In Expression section of the Calculated Value Custom Field you would call the function:
bus_date_subtract();
Note: The function definition can be changed to accept parameters (fields containing dates) that are passed at the time of calling the function from any Calculated Value Custom Field.