Questions and discussion about using ProcessMaker 2: user interface, running cases and functionality
Forum rules: Please search to see if a question has already been asked before posting. Please don't ask the same question in multiple forums.
By nuNceP
#23100
Hi,
I'm using a MySQL query to update due dates for tasks based on date fields. The query I am using is:
Code: Select all
$app=@@APPLICATION;
$proc=@@PROCESS;
$task=@@TASK;
$duedate = date('Y-m-d', strtotime(@@frmNewreq_priority) ) . ' 18:00:00';
$result = executeQuery("UPDATE app_delegation SET DEL_TASK_DUE_DATE='$duedate' WHERE APP_UID='$app' AND PRO_UID='$proc' AND TAS_UID='$task' ORDER BY DEL_INDEX DESC LIMIT 1");   
My problem is that I have to put this query in the task itself, so it only updates after the user has opened the task at least once. How can I get it to update right when it is assigned? I tried to put it in the "after routing" bit of the previous task, but it didn't work, I guess because it gets the wrong @@TASK id. How can I get this done?
User avatar
By amosbatto
#23112
Use this code in a trigger fired after routing of the previous task:
Code: Select all
$caseId = @@APPLICATION;
//lookup the delegation index of the next task in the case
$query = "SELECT MAX(DEL_INDEX) AS NEXT_INDEX FROM APP_DELEGATION WHERE APP_UID='$caseId' ";
$result = executeQuery($query);
$nextIndex = $result[1]['NEXT_INDEX'];
$duedate = date('Y-m-d', strtotime(@@frmNewreq_priority) ) . ' 18:00:00';
$result = executeQuery("UPDATE app_delegation SET DEL_TASK_DUE_DATE='$duedate' 
    WHERE APP_UID='$caseId' AND DEL_INDEX='$nextIndex' ");  
By bilalk
#795653
Adsız.png
Adsız.png (4.11 KiB) Viewed 11728 times
amosbatto wrote:Use this code in a trigger fired after routing of the previous task:
Code: Select all
$caseId = @@APPLICATION;
//lookup the delegation index of the next task in the case
$query = "SELECT MAX(DEL_INDEX) AS NEXT_INDEX FROM APP_DELEGATION WHERE APP_UID='$caseId' ";
$result = executeQuery($query);
$nextIndex = $result[1]['NEXT_INDEX'];
$duedate = date('Y-m-d', strtotime(@@frmNewreq_priority) ) . ' 18:00:00';
$result = executeQuery("UPDATE app_delegation SET DEL_TASK_DUE_DATE='$duedate' 
    WHERE APP_UID='$caseId' AND DEL_INDEX='$nextIndex' ");  
i have a paralel task and this code only set one of them due date as show as image. how can we set all paralel tast due date together?
i am using 2 trigger for that one of them is your another one is yours too but MAX(DEL_INDEX-1) like that
#795668
Let's say that you have a datetime field with the ID "dueDate" where the user can select the date and time when the two parallel tasks should be completed.

Then, use this trigger code after routing in the previous task before the parallel tasks:
Code: Select all
//set to the IDs of parallel tasks 1 and 2:
$parallelTask1Id = 'XXXXXXXXXXXXXXXXXXX';
$parallelTask2Id = 'XXXXXXXXXXXXXXXXXXX';

if (empty(@@dueDate)) {
   throw new Exception("Didn't select the Due Date for next tasks");
}

$caseId = @@APPLICATION;
$dueDate =@@dueDate;

//set the due dates in the two parallel tasks:
$query = "UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$duedate'
   WHERE APP_UID='$caseId' AND (TAS_UID='$parallelTask1Id' OR TAS_UID='$parallelTask2Id') 
   AND DEL_THREAD_STATUS='OPEN' ";
@@setDueDate = executeQuery($query);

$query2 = "UPDATE APP_CACHE_VIEW SET DEL_TASK_DUE_DATE='$duedate'
   WHERE APP_UID='$caseId' AND (TAS_UID='$parallelTask1Id' OR TAS_UID='$parallelTask2Id') 
   AND DEL_THREAD_STATUS='OPEN' ";
@@setDueDate2 = executeQuery($query2);
 
You have to set the IDs of the two parallel tasks. You can find them by looking at the TASK system variable in the debugger while running a case or by searching in the TASK.TAS_UID field in the database.

if using PM 3.0.18 or later, you will also have change your configuration files to be able to write directly to the ProcessMaker tables in the database.
Edit the file workflow/engine/config/execute-query-blacklist.ini in the PM source code and change the following line from:
Code: Select all
queries  = "INSERT|UPDATE|REPLACE|DELETE|TRUNCATE"
To:
Code: Select all
queries  = "INSERT|REPLACE|DELETE|TRUNCATE"
See: http://wiki.processmaker.com/3.0/Consul ... ore_Tables
By richvle
#821921
What if the next task is assigned to a user group, so it isn't actually assigned to any user yet? And the previous tasks were script tasks. Any updates we do prior will effect a previous script task delegation, not the current task delegation.
amosbatto wrote: Mon Jun 11, 2012 9:02 pm Use this code in a trigger fired after routing of the previous task:
Code: Select all
$caseId = @@APPLICATION;
//lookup the user assigned to the next task in the case
$query = "SELECT MAX(DEL_INDEX) AS NEXT_INDEX FROM APP_DELEGATION WHERE APP_UID='$caseId' ";
$result = executeQuery($query);
$nextIndex = $result[1]['NEXT_INDEX'];
$duedate = date('Y-m-d', strtotime(@@frmNewreq_priority) ) . ' 18:00:00';
$result = executeQuery("UPDATE app_delegation SET DEL_TASK_DUE_DATE='$duedate' 
    WHERE APP_UID='$caseId' AND DEL_INDEX='$nextIndex' ");  
User avatar
By amosbatto
#821924
richvle wrote: Wed Dec 05, 2018 4:05 pm What if the next task is assigned to a user group, so it isn't actually assigned to any user yet? And the previous tasks were script tasks. Any updates we do prior will effect a previous script task delegation, not the current task delegation.
There is no way to set the due date of the next task after a script task, because the database record for the next task does not yet exist in the APP_DELEGATION table when the trigger for a script task is fired.

What you need to do is delete your script task and set its trigger to fire after routing in a normal task.

The other option is to set the trigger to fire before the first step in the same task whose due date needs to be set. Most users look at the due date before opening a task, so this is only helpful for users who open the task, but don't immediately complete it. If you do this, then the trigger code would be different:
Code: Select all
$caseId = @@APPLICATION;
$index = @@INDEX;
$dueDate = date('Y-m-d', strtotime(@@frmNewreq_priority) ) . ' 18:00:00';
$result = executeQuery("UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$dueDate' 
    WHERE APP_UID='$caseId' AND DEL_INDEX='$index' ");  
#821935
I tried the second route and it doesn't look like it's updating, or perhaps it's being overwritten. But I agree, I would like the users to be able to see the due date there before they claim the case (at IT Support Review).

As for the first solution, I was able to move some of the trigger into tasks, however, there are certain triggers prior to that that I couldn't because it only gets triggered after a gateway.
Capture2.JPG
Capture2.JPG (76.58 KiB) Viewed 10286 times
#821936
Try also changing it in APP_CACHE_VIEW:
Code: Select all
$caseId = @@APPLICATION;
$index = @@INDEX;
$dueDate = date('Y-m-d', strtotime(@@frmNewreq_priority) ) . ' 18:00:00';
$result = executeQuery("UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$dueDate' 
    WHERE APP_UID='$caseId' AND DEL_INDEX='$index' ");  
$result = executeQuery("UPDATE APP_CACHE_VIEW SET DEL_TASK_DUE_DATE='$dueDate' 
    WHERE APP_UID='$caseId' AND DEL_INDEX='$index' ");
#821952
I added the trigger to "Before Dynaform" for the task as well. And it doesn't kick in. However, when the user claims the case, it moves the case to their inbox and if we look in the inbox, we can see the correct due date.
Capture2.JPG
Capture2.JPG (85.55 KiB) Viewed 10264 times

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

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]