Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

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.
By gregoakes
#790645
Apologies up front - this topic was [SOLVED] in a post in the PM2 forum... viewtopic.php?t=7751

I have tried the code from the PM2 post (below) but have met with no success. I'm not really a programmer - i just feed off the scraps of other peoples' cleverness.

What I am trying to accomplish is have a user set a date (@@completionDate) at the beginning of a process and have that reflected as the Due Date for the next task. I don't want to use the Timing Controls as I want to have the process initiator set the value once and then be able to apply this to later tasks in the process.

I have set the following trigger to fire after routing:
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('DD-MM-YYYY', strtotime(@@completionDate) ) . ' 18:00:00';
$result = executeQuery("UPDATE app_delegation SET DEL_TASK_DUE_DATE='$duedate'
    WHERE APP_UID='$caseId' AND DEL_INDEX='$nextIndex' ");
Has something changed in the last 5 years (?!) that would impact on this trigger running successfully? Is there anything I need to do (or NOT do) in the Task Timing Controls.

Thanks for your patience
Greg
By mishika
#790648
Hello,

The trigger code that has been given in the post you have referred works perfectly, only the name of the table needs to be specified in block letters "APP_DELEGATION" for the update query.
In the trigger code, you have mentioned, the DateTime format should be 'Y-m-d' because this is the format in which the due date is stored in the database and not "DD-MM-YYYY".
Therefore, the trigger code can be:
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(@@completion) ) . ' 18:00:00';
$result = executeQuery("UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$duedate' WHERE APP_UID='$caseId' AND DEL_INDEX='$nextIndex' ");  
This code works for me. Please check if this solves your problem.

Best Regards
Mishika
By gregoakes
#790658
Hi Mishika,

thanks for your reply. The code you have given me works perfectly.

However, I have a set of parallel tasks. The first task gets the Due Date set. The other processes default. Prior to trying this, I was using timing controls if that makes any difference though the first assignment works as hoped for... (?)

cheers

Greg
By mishika
#790661
Hello,

The above code will only work to set the due date of 1 task and not multiple parallel tasks. This is because it is using the MAX(DEL_INDEX) which will provide a unique entry from the table.
To fetch all the parallel entries after a particular task, you can use the following trigger:
Code: Select all
$caseId = @@APPLICATION;
$prev_del_index = @@INDEX;
$duedate = date('Y-m-d', strtotime(@@completion) ) . ' 18:00:00';
$result = executeQuery("UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$duedate' WHERE APP_UID='$caseId' AND DEL_PREVIOUS='$prev_del_index' ");  
This code fetches the DEL_INDEX of current task and uses it as the DEL_PREVIOUS in the query which updates all the tasks just after this task(i.e. all the parallel tasks).

Hope this helps

Best Regards
Mishika

Hello! If you did not find the mcrypt extension […]

Hello! You have a mistake in the url, the correct […]

objects variable in grid

Hello! It is very rare since I could not replicate[…]

Hello! It is likely that the design you are doin[…]