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.
#787866
We have a requirement for the Case Creator/Submitter to click a MODIFY button at any point of the approval flow. Clicking the MODIFY button will do the following:
1. stop the approval flow of the current case he created/submitted; case actors will not be able to approve anymore
2. case # will stay the same; all field values stay the same
3. status is the only thing that will change from TO_DO back to DRAFT
4. he can modify the same case and resubmit again from the start as it was like a DRAFT

How can I achieve for a case to go back in DRAFT status as initiated by the Requester (not by the current approver)?
Please let me know of the javascript and php trigger to use.
Thank you.
#787964
There is no easy way to do this. The easiest route is to simple cancel the case and copy its data to a new case, but that will change the case number and you won't be able to see the case history.

If you want to keep the same case, I recommend redesigning your process to have a loop back to the first task after each task in the process:
loopbackAfterEveryTask.png
loopbackAfterEveryTask.png (11.96 KiB) Viewed 3655 times
Create a string variable in the process named "firstUser". Make the first task have Value Based Assignment and use the variable @@firstUser. Create a trigger which is set to fire before the first step in the first task with the code:
Code: Select all
@@firstUser = @@USER_LOGGED; 
Create a string variable named "restart". For every exclusive gateway add conditions to either continue with the process or route back to the first task:

(!isset(@@restart) or @@restart != 'yes') to continue
(isset(@@restart) and @@restart == 'yes') to route to first task
routingRulesToRestart.png
routingRulesToRestart.png (23.66 KiB) Viewed 3655 times

Then, make another process with one task and a DynaForm step which displays a grid of cases that can be restarted. See this example for the grid to create.

Create this trigger to fire before the DynaForm with the "casesList" grid:
Code: Select all
$userId = @@USER_LOGGED;
$query = "SELECT DISTINCT ACV.APP_UID, ACV.DEL_INDEX, ACV.USR_UID, ACV.APP_NUMBER,
     ACV.APP_PRO_TITLE, ACV.APP_TAS_TITLE, ACV.APP_CURRENT_USER, ACV.APP_UPDATE_DATE,
     ACV.APP_STATUS FROM APPLICATION A, APP_CACHE_VIEW ACV
   WHERE A.APP_INIT_USER='$userId' AND (A.APP_STATUS='DRAFT' OR A.APP_STATUS='TO_DO') AND 
   A.APP_UID=ACV.APP_UID AND ACV.DEL_THREAD_STATUS='OPEN' ORDER BY ACV.APP_NUMBER DESC ";
$aCases = executeQuery($query);
if (!is_array($aCases))
        die("Error in query: $query");

@=casesList = array();
for($i = 1; $i <= count($aCases); $i++) {
   @=casesList[$i] = array(
      'caseId'  => $aCases[$i]['APP_UID'],
      'index'   => $aCases[$i]['DEL_INDEX'],
      'userId'  => $aCases[$i]['USR_UID'],
      'reopen'  => '0',
      'caseNo'  => $aCases[$i]['APP_NUMBER'],
      'process' => $aCases[$i]['APP_PRO_TITLE'],
      'task'    => $aCases[$i]['APP_TAS_TITLE'],
      'user'    => $aCases[$i]['APP_CURRENT_USER'],
      'updated' => $aCases[$i]['APP_UPDATE_DATE'],
      'status'  => $aCases[$i]['APP_STATUS']
   );
}
Then add a second trigger to fire after the DynaForm:
Code: Select all
if (isset(@=casesList) and !empty(@=casesList)) {
   $restartedCases = '';
   foreach (@=casesList as $aCase) {
      if ($aCase['reopen'] == '0') {
         continue;
      }
      PMFSendVariables($aCase['caseId'], array('restart' => 'yes'));
      PMFDerivateCase($aCase['caseId'], $aCase['index']);
      PMFSendVariables($aCase['caseId'], array('restart' => 'no'));

      $c = new Cases();            
      $aCaseInfo = $c->loadCase($aCase['caseId']);
      $aCaseInfo['APP_STATUS'] = 'DRAFT';
      $c->updateCase($caseId, $aCaseInfo);
      $restartedCases .= (empty($restartedCases) ? '' : ', ') . $aCase['caseNo'];
   }
   if ($restartedCases) {
      G::SendMessageText("Case(s) $restartedCases restarted.", "INFO");
   }
}
I haven't tested this code, so it might require some debug, but you get the basic idea.
#787973
Hi Amos.
It surely not an easy flow based on your explanation. We can do some tests on it.

Currently once a case is TO_DO, requester/submitter cannot initiate to withdraw his case back to DRAFT anymore, or TO_MODIFY status.
Is there a possibility for a future Processmaker release to add this functionality (a custom button and/or trigger maybe)?
Do we need to submit an evolution request?

Thanks!
#788008
You can file a bug report at bugs.processmaker.com and ask for a new feature in PM. The forum is not the place to ask for it. Generally new features requests are low priority when the requester doesn't have a support contract, but you can ask.

Frankly, the easiest way to handle this is to simply start a new case with PMFNewCase() and copy the data over. You can place a variable in your case title such as @@caseTitle which is normally set to the Case Number, but for restarted cases is set to "Restarted Case #X"

In the first task, set this trigger:
Code: Select all
if (!isset(@@caseTitle)) {
   @@caseTitle = '#'.@@APP_NUMBER;
}
And in the trigger to restart the case:
Code: Select all
if (@@action == "CANCEL") {
   $aVars = array("caseTitle"=>"Restarted Case#".@@APP_NUMBER );
   $c = new Cases();
   $aCase = $c->LoadCase(@@APPLICATION);
   $aVars = merge_array($aCase[APP_DATA], $aVars);
   unset($aVars['PROCESS']);
   unset($aVars['TASK']);
   unset($aVars['APPLICATION']);
   unset($aVars['APP_NUMBER']);
   unset($aVars['INDEX']);
   unset($aVars['USER_LOGGED']);
   unset($aVars['USR_USERNAME']);
   $processId = 'XXXXXXXXXXXXXXXXXXXXXX';
   $taskId = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
   $userId = $aCase["APP_INIT_USER"];
   $newCaseId = PMFNewCase($processId, $userId, $taskId, $aVars);
   $aNewCase = $c->loadCase($newCaseId); 
   PMFCancelCase(@@APPLICATION, @%INDEX, @@USER_LOGGED);
   die("Restarting this case #".@@APP_NUMBER." as Case #".$aNewCase['APP_NUMBER']);
}   
For buttons to cancel cases, see: http://wiki.processmaker.com/3.0/Submit ... ancel_Case
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[…]