Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By marcosfpa
#787682
Is it possible to do actions on tasks that are in the unassigned box after a certain time?
I'd like 2 options:
1- Assign a user to the task after a deadline without anyone assuming;
2- Or advance the case to the next task after a deadline without anyone taking over or performing the task;

It's possible?

Att,

Marcos Almeida
User avatar
By amosbatto
#787692
You can set a Timeout for the Self Service in Assignment Rules for the Task.
SetATimeout.png
SetATimeout.png (84.5 KiB) Viewed 6209 times
In the trigger code which is executed by the timeout, you can use Cases::setCatchUser() to assign a user to the case:
Code: Select all
$c = new Cases();
$c->setCatchUser(@@APPLICATION, @%INDEX + 1, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
I'm not sure if you should use @%INDEX or @%INDEX+1, but try them both to see which one works.

To automatically route the case on to the next task, use PMFDerivateCase():
Code: Select all
$c = new Cases();
$c->setCatchUser(@@APPLICATION, @%INDEX + 1, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
PMFDerivateCase(@@APPLICATION, @%INDEX + 1);
By marcosfpa
#787707
It did not work TRIGGER, incidentally, I created an email sending trigger and also did not work the time-out. Can it be a problem in time-out? Any additional settings for SELF-SERVICE time-out to work? Any LOG I can visualize the problem?

Marcos Almeida
User avatar
By amosbatto
#787711
If you check your shared/log/cron.log file, you should see lines like this when the timeout executes:
Code: Select all
2016-12-02 22:36:02 |  | unassignedCase | action | Unassigned case
2016-12-02 22:36:03 |  | unassignedCase | action | OK Executed tigger to the case 62
I played with this for a while. What I found is that there appears to be a bug with timeouts. When I have a timeout of 1 minute, it appears to execute a day later. I filed a bug report about it:
https://processmaker.atlassian.net/browse/TRI-2147

The code I gave you to set the user for the task works. I have not found a way to route the case with PMFDerivateCase().

Here is what I do to debug:
Code: Select all
$vars = 
	"ID:".@@APPLICATION.
	"|Index:".@%INDEX.
	"|userID:".@@USER_LOGGED.
	"|username:".@@USR_USERNAME.
	"|taskID:".@@TASK.
	"|CaseNo:".@@APP_NUMBER.
	"|time:". date("Y-m-d H:i:s");

print "\n".$vars ."\n";
file_put_contents("/tmp/variables_".@@APP_NUMBER.".txt", $vars);
$c = new Cases();
$c->setCatchUser(@@APPLICATION, @%INDEX+1, @@USER_LOGGED);
PMFDerivateCase(@@APPLICATION, @%INDEX+1);
When the timeout trigger executes with cron.php, I see:
Code: Select all
root@amos:/opt/pm3.1.2e/workflow/engine/bin# php cron.php
Processing workspace: workflow
* Resending emails............................................[DONE]
* Unpausing applications......................................[DONE]
* Calculating Duration........................................[DONE]
* Calculating Duration by Application.........................[DONE]
* Executing events............................................[PROCESSING]
* |- End Execution events.....................................[Processed 0]
* Executing the scheduled starting cases......................[PROCESSING]
[DONE]
* Update case labels..........................................[DONE]
* Unassigned case.............................................
ID:80674216458408647ae57b7038481755|Index:1|userID:00000000000000000000000000000001|username:admin|taskID:7519239045840842798fdb2029373106|CaseNo:62|time:2016-12-02 22:36:02
[DONE]
* Executing cron files in bin/plugins directory in Workspace: workflow
Finished 1 workspaces processed
Done!
And I see the file /tmp/variables_62.txt has been created.
By marcosfpa
#787762
We are almost there.
It worked for me TRIGGERS with Devitave Case and Email, but the setCatchUser function does not work at all. I need the current unassigned task to be assigned to a specific user, the setCatchUser function did not work for me, only Derivate Case but this function advances to the next task and needs to stay in the current one. SetCatchUser worked for you?
Any other ideas?

Att,
Marcos Almeida
User avatar
By amosbatto
#787781
Yes, setCatchUser() worked for me. Remember that the user set by setCatchUser() has to be in the assignment pool for the self service task.
By marcosfpa
#788169
I still have no solution for that. Can it be the version? I am using 3.1.2 Community.
Now I've tried another script that is in WIKI and it also did not work. What's wrong with him?
Code: Select all
$taskId = '476017029584e82aa85d0e6085211530'; //set to the ID of the self service task
$caseId = @@APPLICATION;
//lookup delegation index of self service task in database:
$sql = "SELECT DEL_INDEX FROM APP_DELEGATION WHERE APP_UID='$caseId' AND 
   TAS_UID='$taskId' ORDER BY DEL_INDEX DESC";
$aDelegations = executeQuery($sql) or 
   throw new Exception("Error in DB query: $sql");
if (count($aDelegations) == 0) {
   throw new Exception("Unable to find delegation index for self service task with query: $sql");
}
$index = $aDelegations[1]['DEL_INDEX'];
$d = new Derivation();
$aUsers = $d->getAllUsersFromAnyTask($taskId);
$cnt = count($aUsers);
if ($cnt > 0) {
   $userToAssign = $aUsers[rand(0, $cnt - 1)];
   $aUser = userInfo($userToAssign);
   $to = $aUser['firstname'].' '.$aUser[lastname].' <'.$aUser['mail'].'>';
   $c = new Cases();
   $c->setCatchUser(@@APPLICATION, $taskId, $userToAssign);
   PMFSendMessage(@@APPLICATION, 'bpms@optimizebpm.com.br', $to, '', '', 
      "You're assigned to case #".@@APP_NUMBER, 'caseAssignment.html', array());
   }
User avatar
By amosbatto
#788260
Did you set this trigger to execute after routing in the previous task? There can't be any events between the two tasks.
Code: Select all
This will work:
[previous task] -> [self service task]

This will not work:
[previous task] -> <event> ->[self service task]
By StephanS
#790523
In that specific timeout-configuration (Self-Service-Timeout), it would be nice to have the pissibility to send a "reminder Notification" to all assigned users and/or groups (guess there meanwhile is a function PMFSendMessageToGroups) if no one claims the task.

To achieve that and write one trigger for use at many parallel tasks I`m trying to fetch the TASK-ID of the task running the timout-trigger while it is executed. But @@TASK delivers the ID of the latest active task and not of the task running that timeout-trigger.
Thinking, that trigger are executed by cron and may not be aware of any relation to a task.

:?: Any idea, how a trigger can identify its related task ? :?:
Or even better: any idea how to achieve a reminder notification, which I do not have to recode for every task ?


This is my actual timeout-trigger (not working):
Code: Select all
// identify task running the timeout-trigger
$currentTask = @@TASK;

// query group-assignment of the task
$result = executeQuery("SELECT USR_UID from TASK_USER where TAS_UID='" . $currentTask . "' and TU_TYPE=1 and TU_RELATION=2");

// send mail if there are groups
if (count($result) >0) {
   foreach ($result as $res) {
      PMFSendMessageToGroup($res, @@APPLICATION, 'ProcessMaker <info@mydomain.de>', "Reminder: There are Cases waiting...", 'ReminderMail.html');
   }
}
Thanks
User avatar
By amosbatto
#790547
Stephan,
The problem is that @@TASK system variable is probably set to the last opened task and not the current task. See:
http://wiki.processmaker.com/3.1/Triggers#Timeouts

You need to manually look up the ID of the task in the TASK.TAS_UID field in the database or use the PMFGetUidFromText() function to look it up.

For example:
Code: Select all
$currentTask = PMFGetUidFromText("My Task Title", 'TAS_TITLE', @@PROCESS, @@SYS_LANG)[0];
By StephanS
#790550
Thank you Amos.

Than, I was on the right way. Here is my solution (you have to create separate triggers for each desired self-service-assigned task)
I created a trigger-template, which just needs the manual configuration of a few variables for each task.
The trigger sends out an eMail to all assigned users and groups !

Limitation: If a user is assigned two times to the task (f.e. group + user), he will receive two mails.

1. create/copy the trigger and name it unique (f.e. with taskname in the triggername)
2. change the variable $taskname to the name of the task with the self-service assignment (exact match)
3. change $MailSender and $MailSubject to your desire
4. create a html-template and name it in the variable $MailTemplate

Then, you can use this trigger in the timeout-section of the self-service-assignment of that task.
Code: Select all
// Please fill variables:
// ===========================
$taskname = "do something";
$MailSender = 'My-ProcessMaker <info@processmaker.mydomain.de>';
$MailSubject = "Reminder: There are unassigned cases !";
$MailTemplate = 'ReminderMail.html';
// ===========================

// --------------------
// identify the Task-ID
// --------------------
$taskID=PMFGetTaskUID($taskname, @@PROCESS);

// ----------------
// Mails to groups
// ----------------
// TU_TYPE represents association-type: direct(1) or adhoc(2)
// TU_RELATION represents user(1) or grupps(2)
$resultG = executeQuery("SELECT USR_UID from TASK_USER where TAS_UID='" . $taskID . "' and TU_TYPE=1 and TU_RELATION=2");
if (count($resultG) >0) {
	foreach ($resultG as $rowG) {
	$toG = $rowG['USR_UID'];
	PMFSendMessageToGroup($toG, @@APPLICATION, $MailSender, $MailSubject, $MailTemplate, array(''), array(''), true, 0, "");
	}
}

// --------------
// Mails to users
// --------------
// TU_TYPE represents association-type: direct(1) or adhoc(2)
// TU_RELATION represents user(1) or grupps(2)
$resultU = executeQuery("SELECT USR_UID from TASK_USER where TAS_UID='" . $taskID . "' and TU_TYPE=1 and TU_RELATION=1");
if (count($resultU) >0) {
	foreach ($resultU as $rowU) {
	$UserID = $rowU['USR_UID'];
	$aUser = userInfo($UserID);
	$toU = $aUser['mail'];
	PMFSendMessage(@@APPLICATION, $MailSender, $toU, '', '', $MailSubject, $MailTemplate, array());
	}
}
Maybe anyone can use it ...
Have a nice weekend,
Stephan
By StephanS
#790577
Thank you again Amos,

I was not aware of this function. The Trigger gets more simple and no duplicates are send :)
(I do not repost it here, because the resulting trigger is nearly the code from wiki )

Use the latest verified Temu coupon $100 off ([acq[…]

To get $100 off, sign up as a new user using refer[…]

To get $100 off, sign up as a new user using refer[…]

To get $100 off, sign up as a new user using refer[…]