Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#793196
I have a need that is to calculate dates considering the calendar set up in ProcessMaker, is it possible?

Example: I have a process that calculates the term of the following tasks according to the final deadline of delivery of that product. So I need to perform calculations based on that final date, but considering the calendar registered in ProcessMaker.
#793228
I did not understand with this code how to calculate.
To be more precise in what I need:
1- I need to monitor an expiration date and 5 hours before that date send an email alert to the manager. Except that these 5 hours should be considering the ProcessMaker calendar date and not normal date ...
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 ...
#793338
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 all
array(
  "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 all
G::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.
By yayirove
#793829
Hello everyone,
I made a holiday process in the PM and I want to use the calendar (located in Admin-> users-> calendar) to define holidays and weekends. Does anyone know how I could do it?
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]