Raman,
PMFRedirectToStep() is only used to redirect to a step in the current task. You will have to add exclusive gateways and a route back to the original task after every task. ProcessMaker only allows cases to be routed along paths in the process map.
Another option is to start a new case with PMFNewCaseImpersonate() in a trigger and pass all the variables from the current case to the new case. Then, cancel the current case.
Here would be the trigger code:
Code: Select all$aSystemVars = array('SYS_SYS', 'SYS_LANG', 'SYS_SKIN', 'APPLICATION', 'INDEX', 'PROCESS', 'TASK',
'USER_LOGGED', 'USR_USERNAME', 'APP_NUMBER', 'PIN', '__ERROR__');
if (@@restartCase == 'yes') {
//get user who started this case:
$c = new Cases();
$aCase = $c->LoadCase(@@APPLICATION);
$firstUserId = $aCase['APP_INIT_USER'];
//remove the system variables from the variables to pass to the new case:
$aVars = $aCase['APP_DATA'];
unset($aVars['restartCase']);
foreach ($aCase['APP_DATA'] as $varName => $varValue) {
if (in_array($varName, $aSystemVars)) {
unset($aVars[$varName]);
}
}
//start a new case with the data and first user from the current case:
if (PMFNewCaseImpersonate(@@PROCESS, $firstUserId, $aVars)) {
//lookup the new case in the database:
$sql = "SELECT MAX(APP_NUMBER) AS CASE_NUMBER FROM APPLICATION WHERE PRO_UID='".
@@PROCESS."' AND APP_INIT_USER='$firstUserId'";
$result = executeQuery($sql);
if (empty($result)) {
throw new Exception("Unable to find new case in APPLICATION table");
}
$newCaseNo = $result[1]['CASE_NUMBER'];
$aUser = $userInfo($firstUserId);
$fullName = $aUser['firstname'] .' '. $aUser['lastname'] .' ('. $aUser['username'] .')';
//send email to the first user informing him/her that the case has been restarted
PMFSendMessage(@@APPLICATION, 'admin@example.com', $aUser['mail'], '', '',
'Case #'.@@APP_NUMBER.' restarted as case #'.$newCaseNo, 'restartedCase.hmtl');
//cancel the current case:
PMFCancelCase(@@APPLICATION, @%INDEX, @@USER_LOGGED);
print "Current Case #".@@APP_NUMBER.
" canceled and restarted as case #$newCaseNo assigned to $fullName.";
die;
}
}
(This code might require some debug, since I'm writing it off the top of my head, but it gives you the basic idea.)
Set this trigger to fire before assignment in every task in the process.
Then, add a button with the ID "restartCaseButton" and a hidden field with the ID and variable "restartCase" to your Dynaforms.
Then, add this JavaScript to your Dynaforms:
Code: Select all$("#restartCaseButton").find("button").click(function(){
$("#restartCase").setValue("yes");
});
This is the basic idea of what this JavaScript is doing:
https://wiki.processmaker.com/3.0/Submi ... ancel_Case
Finally, add an email template with the filename "restartedCase.html" that is used by PMFSendMessage().