marcosfpa wrote:2- And I have a process where I define the next task deadline based on the type of product. So I need to calculate a date from the current date and time adding the custom deadline (1 day, 2 days, etc) but considering the system calendar date ...
To calculate the due date for a task, you need to use dates::calculateDate().
Definition:
dates::calculateDate() is used to calculate the due date for a task (or any projected datetime), based on the configured calendar or work days if $iTypeDay is set to 1. The calendar is selected first based on the user. If there is no selected calendar for the user, then use the selected calendar for the task. If no calendar is selected for the task, then use the selected calendar for the process. If not calendar is selected for the process, then use the default calendar for the workspace.
array calculateDate($sInitDate, $iDuration, $sTimeUnit, $iTypeDay, $UsrUid = null, $ProUid = null, $TasUid = null)
Parameters:
$sInitDate: Start Date in "YYYY-MM-DD HH:MM:SS" format
$iDuration: Integer which represents number of time units
$sTimeUnit: Type units in 'DAYS' or 'HOURS'
$iTypeDay: Set to 1 if calculating work days (Monday-Friday) or 2 for calendar days.
$UsrUid: Set to the unique ID of the user. If not included or set to null, then don't search for a calendar set for a particular user.
$ProUid: Set to the unique ID of the process. If not included or set to null, then don't search for a calendar set for a particular process.
$TasUid: Set to the unique ID of the task. If not included or set to null, then don't search for the calendar set for a particular task.
Return Value:
Code: Select allarray(
"DUE_DATE" => "2017-06-23 17:00:00", //end date in "YYYY-MM-DD HH:MM:SS"
"DUE_DATE_SECONDS" => 1498251600, //timestamp in seconds for end date
"DUE_DATE_LOG"] => "..." //log to select calendar and calculate date
)
You would use trigger code like this:
Code: Select allG::LoadClass('dates');
$d = new dates();
$startDate = date("Y-m-d H:i:s"); //current datetime
if (isset@@typeTask) and @@typeTask == 'simple') {
$duration = 10;
$timeUnits = 'HOURS';
}
else {
$duration = 2;
$timeUnits = 'DAYS';
}
$ret = $d->calculateDate($startDate, $duration, $timeUnits, 2, @@USER_LOGGED, @@PROCESS, @@TASK);
$endDate = $ret['DUE_DATE'];
$caseId = @@APPLICATION;
$index = @@INDEX;
$sql = "UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$endDate' WHERE APP_UID='$caseId' AND DEL_INDEX=$index";
executeQuery($sql);
$sql = "UPDATE APP_CACHE_VIEW SET DEL_TASK_DUE_DATE='$endDate' WHERE APP_UID='$caseId' AND DEL_INDEX=$index";
executeQuery($sql);
Where @@typeTask is a variable that you set in a prior DynaForm. Set this trigger to fire either in the task whose due date needs to be set or
after routing in the prior task, because at that point, records for the case's task have already been created in the APP_DELEGATION and APP_CACHE_VIEW tables in the database.