Article: AN0001899Updated: 03.10.2018
Calendars are used in ObjectGears for determining time windows, within which the time should be calculated (e.g. for calculating target time according to SLA). Calendars are defined in classes that contain data about standard times and exceptions. The exceptions have various recurrence frequency (e.g. a fixed date for holidays, monthly recurrence etc.)
Initialization
Before using calendar it is necessary to perform its initialization. The initialization has to be called in the Application event After application start according to the documentation.
Where to use this script: Script in Application events After application start
//setting for calendar initialization
OG.Utils.InitScriptBlockCode = 'init_calendar';
OG.Utils.InitScriptFunctionName = 'Init_Calendar_Server_Team';
Where to use this script: Script block
function Init_Calendar_Server_Team()
{
var k = OGCalculateWorkTime.Configuration; k.Model_DayInWeek_Code= 'common_data';
k.Column_DayInWeek_DayIndex_Code = 'day_number_type_2';
k.Model_Months_Code = 'common_data';
k.ClassDef_Months_Code = 'month';
k.Model_DayOccurrenceInMonth_Code = 'common_data';
//k.Column_ExcPatternYearlyFloat_Month_Code = 'every_x_month';
}
Value calculation
In order to use calendar use following script.
Where to use this script: Rule before record saving
var dt = OGActualDataRow['date-and-time'];
if ( dt != null)
{
var hour = 8; // 8 hours
var cal = OG.Utils.CreateCalculateWorkTime('Server_team_working_hours');
cal.Initialize();
var de = cal.CalculateEndDate( dt, hour * 60);
OGActualDataRow['target-resolution'] = de;
}
Changes in calendar data
After each change in data with which the calendar is working, it is necessary to clear the calendar cache. Otherwise the calendar is working with the old data.
Where to use this script: Tlačítko
OG.Utils.ClearAllCalculateWorkTime();